fix(worker): bound each STA message-pump pass to 64 dispatches (WIP-001, #246)
ci / portable (push) Failing after 13m57s
ci / windows-x86 (push) Successful in 12m20s
ci / java (push) Failing after 40m28s
ci / portable (push) Failing after 13m57s
ci / windows-x86 (push) Successful in 12m20s
ci / java (push) Failing after 40m28s
An unbounded PeekMessage drain never returned while inbound COM callbacks arrived at least as fast as they dispatched, so the STA loop stopped running queued commands and stopped stamping LastActivityUtc; the heartbeat watchdog then faulted a busy apartment as StaHung. The record-info pin raises the dispatch ceiling a lot but is best-effort, and the drain was still unbounded. Each pump pass now dispatches at most StaMessagePump.MaxMessagesPerPass (64), then the loop stamps activity and services the command queue. MWMO_INPUTAVAILABLE makes the next wait return at once while input remains, so no wakeup is lost. StaRuntime.PumpPendingMessages (the pump step of ReadBulk/write waits) uses the same cap so those loops re-check their deadline between slices. Tests: a fake message flood with a queued command (command runs, activity stays fresh, no pass exceeds the cap); a real-queue test that a pass stops at the cap.
This commit is contained in:
@@ -255,11 +255,18 @@ while not shutdown:
|
||||
QS_ALLINPUT,
|
||||
MWMO_INPUTAVAILABLE)
|
||||
|
||||
while PeekMessage:
|
||||
repeat at most 64 times while PeekMessage:
|
||||
TranslateMessage
|
||||
DispatchMessage
|
||||
```
|
||||
|
||||
Each pump pass dispatches at most `StaMessagePump.MaxMessagesPerPass` (64)
|
||||
messages, then the loop stamps activity and returns to the command queue. An
|
||||
unbounded drain never returns while COM callbacks arrive at least as fast as
|
||||
they dispatch, so queued commands would not run and the activity stamp would
|
||||
freeze until the watchdog reported `StaHung`. `MWMO_INPUTAVAILABLE` makes the
|
||||
next wait return at once while input remains, so the cap loses no wakeups.
|
||||
|
||||
The command queue should signal a Win32 event or equivalent wait handle so the
|
||||
STA can wake without busy-waiting.
|
||||
|
||||
@@ -338,11 +345,14 @@ message wake is what carries it.
|
||||
|
||||
`MWMO_INPUTAVAILABLE` makes the drain contract load-bearing: the wait wakes on
|
||||
input that is merely *present*, including input an earlier `PeekMessage` saw but
|
||||
did not remove. A `pumpStep` that drains only part of the queue — or a no-op one
|
||||
— therefore leaves a message that satisfies the wake condition forever, and the
|
||||
did not remove. A `pumpStep` that removes nothing — a no-op, or a peek without
|
||||
`PM_REMOVE` — therefore leaves a message that satisfies the wake condition forever, and the
|
||||
loop spins at 100% CPU until its deadline (deadline and reply shape still hold;
|
||||
it is a CPU fault, not a correctness one). Every `pumpStep` must drain to empty,
|
||||
as `StaRuntime.PumpPendingMessages` does.
|
||||
it is a CPU fault, not a correctness one). Every `pumpStep` must remove messages
|
||||
on each call. `StaRuntime.PumpPendingMessages` removes up to 64 per call: a
|
||||
backlog larger than that makes the next wait return at once, and the next step
|
||||
dispatches the next slice, so the loop only stays busy while there is real
|
||||
dispatch work and re-checks its deadline between slices.
|
||||
|
||||
The wait slice is capped at 50 ms so `pumpStep` runs periodically even when
|
||||
nothing wakes the wait — a process with no STA message queue (unit tests drive
|
||||
|
||||
Reference in New Issue
Block a user