fix: resolve reply-bearing X11 liveness cookies with Reply (#2)
Build Ground Station / build (push) Successful in 26s

This commit was merged in pull request #14.
This commit is contained in:
2026-10-02 10:42:07 +02:00
parent 2ced44b47b
commit ffae3560c4
2 changed files with 200 additions and 6 deletions
+55 -6
View File
@@ -178,6 +178,44 @@ func (o X11Opener) pollInterval() time.Duration {
return 100 * time.Millisecond
}
// livenessRequest is one liveness round trip on a connection: it resolves
// its request and reports only the error.
type livenessRequest func() error
// connLivenessProbe returns the liveness round trip used after mapping a
// window and while a session waits for events. GetInputFocus carries a
// reply, so its cookie must be resolved with Reply: calling Check on a
// reply-bearing cookie fails at runtime with the XGB reply-cookie error
// ("Cannot call 'Check' on a cookie that is expecting a *reply*"), which
// killed every layer open and reconnect on the device.
func connLivenessProbe(conn *xgb.Conn) livenessRequest {
return func() error {
return resolveLiveness(xproto.GetInputFocus(conn))
}
}
// resolveLiveness consumes one issued reply-bearing liveness cookie: the
// reply is read and discarded, and only the error propagates. The cookie
// must be resolved with Reply exactly once — Check on a reply-bearing
// cookie returns the XGB reply-cookie error instead of ever reaching the
// server, so a probe resolved with Check fails on every call regardless of
// server health.
func resolveLiveness(cookie xproto.GetInputFocusCookie) error {
_, err := cookie.Reply()
return err
}
// confirmMapped runs the post-map liveness stage of Open: a successful
// reply proves the window is mapped and the server alive; a failure is
// wrapped as the map-kiosk-window error so the caller closes the
// connection and drops the mapped window.
func confirmMapped(probe livenessRequest) error {
if err := probe(); err != nil {
return fmt.Errorf("map kiosk window: %w", err)
}
return nil
}
// Open connects to the X server and maps the kiosk window. Failure is
// expected while the display manager is starting; the caller retries.
func (o X11Opener) Open(ctx context.Context) (Session, error) {
@@ -239,10 +277,12 @@ func (o X11Opener) Open(ctx context.Context) (Session, error) {
// destroy is video end. WFB and launcher processes are never consulted.
xproto.ChangeWindowAttributes(conn, screen.Root,
xproto.CwEventMask, []uint32{xproto.EventMaskSubstructureNotify})
// Round trip confirms the window is mapped and the server is alive.
if err := xproto.GetInputFocus(conn).Check(); err != nil {
// Round trip confirms the window is mapped and the server is alive;
// the reply-bearing cookie is resolved with Reply (see
// connLivenessProbe).
if err := confirmMapped(connLivenessProbe(conn)); err != nil {
conn.Close()
return nil, fmt.Errorf("map kiosk window: %w", err)
return nil, err
}
// A layer reconnect must never cover running video: if video windows
@@ -301,6 +341,8 @@ func (o X11Opener) Open(ctx context.Context) (Session, error) {
markerAtom: markerAtom,
role: o.Role,
unicodeFont: unicodeFont,
pollEvent: conn.PollForEvent,
probe: connLivenessProbe(conn),
}, nil
}
@@ -560,6 +602,12 @@ type x11Session struct {
markerAtom xproto.Atom
role LayerRole
unicodeFont bool
// pollEvent drains one pending X event; conn.PollForEvent in
// production. Tests script it.
pollEvent func() (xgb.Event, xgb.Error)
// probe performs one reply-bearing liveness round trip; its error ends
// the session. connLivenessProbe in production. Tests script it.
probe livenessRequest
}
func (s *x11Session) Canvas() Canvas { return s }
@@ -598,7 +646,7 @@ func (s *x11Session) WaitEvent(ctx context.Context) (bool, error) {
defer ticker.Stop()
for {
for {
event, err := s.conn.PollForEvent()
event, err := s.pollEvent()
if err != nil {
return false, err
}
@@ -613,8 +661,9 @@ func (s *x11Session) WaitEvent(ctx context.Context) (bool, error) {
}
}
// Round trip keeps the connection liveness visible even without
// incoming events.
if err := xproto.GetInputFocus(s.conn).Check(); err != nil {
// incoming events; the reply-bearing cookie is resolved with Reply
// (see connLivenessProbe).
if err := s.probe(); err != nil {
return false, err
}
select {