[WIP-001] Unbounded STA message-pump drain starves commands; sustained event load reported as StaHung #246
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
WIP-001: Unbounded message-pump drain starves STA commands and the activity stamp
perf.md.Sta/StaMessagePump.cs:44-56,Sta/StaRuntime.cs:335-341,Sta/StaRuntime.cs:404-423,Ipc/WorkerPipeSession.cs:1445-1493Description.
StaMessagePump.PumpPendingMessagesloopswhile (PeekMessage(PM_REMOVE))with no message or time bound. The STA loop calls it and only afterwards callsMarkActivity()and returns toProcessQueuedCommands(). Nothing on the event path (MxAccessBaseEventSink.EnqueueEvent) stamps activity. While inbound messages arrive at least as fast as they dispatch, the pump never returns, so:LastActivityUtcfreezes even though the STA is doing useful work.InvokeAsyncwork items do not run.commandWakeEventis signalled but nothing looks at the queue. This includes the alarm poll and anyUnAdvise/RemoveItema client sends to shed load.The watchdog (
ReportWatchdogFaultIfNeededAsync) sees staleness aboveHeartbeatGrace(15 s) with no command in flight, sets_state = Faultedand writesWorkerFault{StaHung}. The gateway faults the session on anyWorkerFault(Server/Workers/WorkerClient.cs:682-686).Failure scenario.
perf.mdmeasures about 1.4 ms of STA time perOnDataChangeon vd03 at HEAD (the record-info pin is not merged, see WIP-002). That caps dispatch near 700 events/s. A client that advises enough fast-changing tags to exceed that rate for more than 15 s gets its session killed with "STA activity is stale", a diagnosis that points at a hung COM call. The event queue never overflows because the drain loop keeps up, so the designedQueueOverflowfail-fast does not fire first. With a command in flight the same load is tolerated only untilHeartbeatStuckCeiling(75 s), and that command does not start in the meantime.Suggested fix. Bound each pump pass (for example 64 messages or about 10 ms), call
MarkActivity()inside the pump loop, and interleaveProcessQueuedCommands()between slices.MWMO_INPUTAVAILABLEalready makes the next wait return immediately when messages remain, so a bounded pass loses no wakeups.Test idea. Drive
StaRuntimewith a fakeIStaMessagePumpwhosePumpPendingMessagessimulates a backlog that refills for N seconds. Assert thatLastActivityUtcadvances during the backlog and that anInvokeAsyncqueued mid-backlog completes before it ends.Source:
code-reviews/2026-12-02-perf-bugs/README.mdandcode-reviews/2026-12-02-perf-bugs/PLAN.md(commitf200bda6on local branchdocs/review-2026-12-02-perf-bugs, not yet pushed). Reviewed at54367e74.Merged to
mainat68043411(pushed 2026-12-03). Gateway suite 1610 passed / 0 failed (macOS); windev worker CI 836 passed / 0 failed on that SHA.STA pump drains at most 64 messages per pass, then services commands and stamps activity. Flood test added.