Galaxy: can an MXAccess initial value arrive on the event stream before the driver registers the new item handle? #859

Closed
opened 2026-11-11 10:01:34 -05:00 by dohertj2 · 1 comment
Owner

Possible production gap, unverified — found while fixing #856. The event pump drops an event whose item handle is not (yet) in the subscription registry as "stale after unsubscribe". SubscribeAsync and PerPlatformProbeWatcher register a handle only after the gateway's subscribe reply returns. MXAccess delivers an initial value on subscribe; if mxaccessgw can put that first MxEvent on the stream before the subscribe reply reaches us, the initial value is dropped and the node stays at its pre-subscribe value/quality until the next change (a slow-changing or static attribute would stay stale). Check the gateway's ordering guarantee (subscribe reply vs first OnDataChange for that handle); if not guaranteed, buffer unknown-handle events briefly or register before the reply.

Possible production gap, unverified — found while fixing #856. The event pump drops an event whose item handle is not (yet) in the subscription registry as "stale after unsubscribe". `SubscribeAsync` and `PerPlatformProbeWatcher` register a handle only after the gateway's subscribe reply returns. MXAccess delivers an initial value on subscribe; if mxaccessgw can put that first `MxEvent` on the stream before the subscribe reply reaches us, the initial value is dropped and the node stays at its pre-subscribe value/quality until the next change (a slow-changing or static attribute would stay stale). Check the gateway's ordering guarantee (subscribe reply vs first OnDataChange for that handle); if not guaranteed, buffer unknown-handle events briefly or register before the reply.
dohertj2 added the type:followuppriority:p3cross-repo labels 2026-11-11 10:01:34 -05:00
Author
Owner

Fixed (1a31e3f5, f89e0cc0, d08e9002, 133bc07d, a8d3790b). Pushed to master in e857135e. The drop was real: mxaccessgw's worker completes the SubscribeBulk reply asynchronously while the STA loop immediately pumps OnDataChange, and the reply (unary) and events (stream) are separate HTTP/2 streams anyway — the first value could beat the reply and was dropped as "stale after unsubscribe" (subscriptions kept the old value until the next change; subscribe-once reads timed out). Fix: pending-subscribe windows park unknown-handle events (bounded, sequence-trimmed), promoted atomically on Register/Rebind and replayed in order on the dispatch thread; reads, subscribes, replay and probe watcher all open windows; UnsubscribeBulk purges parked events. Four independent concurrency reviews; each round's blockers fixed (ordering race, cross-session handle reuse, read cleanup unsubscribing a reused handle, probe replay skip). Also fixed while testing: a read waiting across a reconnect never saw its value (listened on the replaced pump). Residuals: a same-session reused handle can still receive an in-flight stale event (full fix needs a worker sequence on the SubscribeBulk reply in mxaccessgw — optional, documented); a subscribe landing between the two reopen-time session bumps can leak one gateway advise.

Fixed (`1a31e3f5`, `f89e0cc0`, `d08e9002`, `133bc07d`, `a8d3790b`). Pushed to master in `e857135e`. **The drop was real:** mxaccessgw's worker completes the SubscribeBulk reply asynchronously while the STA loop immediately pumps OnDataChange, and the reply (unary) and events (stream) are separate HTTP/2 streams anyway — the first value could beat the reply and was dropped as "stale after unsubscribe" (subscriptions kept the old value until the next change; subscribe-once reads timed out). Fix: pending-subscribe windows park unknown-handle events (bounded, sequence-trimmed), promoted atomically on Register/Rebind and replayed in order on the dispatch thread; reads, subscribes, replay and probe watcher all open windows; UnsubscribeBulk purges parked events. Four independent concurrency reviews; each round's blockers fixed (ordering race, cross-session handle reuse, read cleanup unsubscribing a reused handle, probe replay skip). Also fixed while testing: a read waiting across a reconnect never saw its value (listened on the replaced pump). Residuals: a same-session reused handle can still receive an in-flight stale event (full fix needs a worker sequence on the SubscribeBulk reply in mxaccessgw — optional, documented); a subscribe landing between the two reopen-time session bumps can leak one gateway advise.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/lmxopcua#859