fix: bound the event drain so the OSD timer punch survives storms (#3)

This commit is contained in:
2026-11-06 16:37:39 +01:00
parent b7e054e949
commit 5d067ee82d
2 changed files with 116 additions and 1 deletions
+16 -1
View File
@@ -206,6 +206,16 @@ func createWindowValues(backPixel uint32, eventMask uint32, cursor xproto.Cursor
// only as a downstream BadWindow.
const cursorBitmapDepth = 1
// eventDrainBatch bounds how many pending events one wait cycle drains. A
// busy server (video fullscreen repaints) can serve unrelated non-Expose
// events faster than they arrive; an unbounded drain would never reach the
// timer checks, so the OSD overlay's initially empty bounding shape would
// never be punched and its telemetry would never appear. Thirty-two events
// per 100 ms poll cycle sustains well over three thousand events per
// second — orders of magnitude above any plausible root-event rate — while
// bounding liveness and cancellation latency to a single batch.
const eventDrainBatch = 32
// blankCursorX is the checked X-request surface of the blank cursor setup,
// so the sequence can be driven by tests that script failures at exact
// operations and pin request order and resource reclamation.
@@ -956,7 +966,12 @@ func (s *x11Session) WaitEvent(ctx context.Context) (bool, error) {
defer ticker.Stop()
lastRefresh := time.Now()
for {
for {
// Drain a bounded batch of pending events: a busy server (video
// fullscreen repaints) can serve unrelated non-Expose events faster
// than they arrive, and an unbounded drain would never reach the
// timer checks — the OSD overlay's initially empty bounding shape
// would never be punched and its telemetry would never appear.
for drained := 0; drained < eventDrainBatch; drained++ {
event, err := s.pollEvent()
if err != nil {
return false, err