Review 2026-12-02 Phase 2: Session and worker lifecycle fixes #253

Closed
opened 2026-12-02 16:07:37 -05:00 by dohertj2 · 2 comments
Owner

Phase 2 — Session and worker lifecycle (p1)

# Finding(s) Change
2.1 SES-001 Close sessions gracefully before Kestrel's stream drain. Do it in an IHostApplicationLifetime.ApplicationStopping callback (or a hosted service registered to stop first): close all sessions (workers shut down cleanly), which completes the open StreamEvents. Keep the kill as a fallback after a bounded grace.
2.2 DSH-002, DSH-007 The dashboard live read closes its session in finally (or on any non-faulting failure). Track advised tags before awaiting, so a cancelled subscribe can still unadvise.
2.3 SES-004 Lease expiry must not close a session that is detached but still inside DetachGraceSeconds. Take the later of the two deadlines, or renew the lease while the stream is attached.
2.4 SES-005 (+ client keepalive in Phase 6) Configure Kestrel HTTP/2 keepalive (Http2.KeepAlivePingDelay/Timeout) under MxGateway:* with defaults, validate it in GatewayOptionsValidator, and document it in docs/GatewayConfiguration.md.
2.5 WRK-001, WRK-004 Command timeouts must not reset the heartbeat stuck-ceiling; track the last real worker reply separately. In the timeout arm, check whether the reply already completed before throwing.
2.6 WRK-002, WRK-006 The pipe-connect wait races Process.WaitForExitAsync. On early exit, report the exit code and stderr tail. Launch-failure cleanup wraps Kill in try/catch and always disposes the pipe.
2.7 WRK-003 Include the outbound enqueue in the command deadline.
2.8 WRK-005 Use TimeProvider / Stopwatch monotonic time for heartbeat staleness.
2.9 WRK-008, SES-007 Guard EventReceived against re-creating a removed session entry (check a removed flag, or remove under the same lock). Unregister purges the session's item registrations.
2.10 WRK-009 Orphan cleanup kills only workers whose command line or pipe name carries a gateway PID that is no longer alive.
2.11 MXA-003, WIP-007, WIP-009 Cover the alarm poll join and handler dispose with the shutdown timeout. The watchdog ignores ShuttingDown. Keep a pipe read outstanding, or a parent-PID check, during MXAccess startup, and put a timeout on the hello read.

Verify: gateway build + Session*, WorkerClient*, GatewayEndToEndFakeWorkerSmokeTests. Worker items (2.11) also need the windev x86 build and Worker.Tests.

High findings filed separately:


Source: code-reviews/2026-12-02-perf-bugs/README.md and code-reviews/2026-12-02-perf-bugs/PLAN.md (commit f200bda6 on local branch docs/review-2026-12-02-perf-bugs, not yet pushed). Reviewed at 54367e74.

## Phase 2 — Session and worker lifecycle (p1) | # | Finding(s) | Change | |---|---|---| | 2.1 | SES-001 | Close sessions gracefully before Kestrel's stream drain. Do it in an `IHostApplicationLifetime.ApplicationStopping` callback (or a hosted service registered to stop first): close all sessions (workers shut down cleanly), which completes the open `StreamEvents`. Keep the kill as a fallback after a bounded grace. | | 2.2 | DSH-002, DSH-007 | The dashboard live read closes its session in `finally` (or on any non-faulting failure). Track advised tags before awaiting, so a cancelled subscribe can still unadvise. | | 2.3 | SES-004 | Lease expiry must not close a session that is detached but still inside `DetachGraceSeconds`. Take the later of the two deadlines, or renew the lease while the stream is attached. | | 2.4 | SES-005 (+ client keepalive in Phase 6) | Configure Kestrel HTTP/2 keepalive (`Http2.KeepAlivePingDelay/Timeout`) under `MxGateway:*` with defaults, validate it in `GatewayOptionsValidator`, and document it in `docs/GatewayConfiguration.md`. | | 2.5 | WRK-001, WRK-004 | Command timeouts must not reset the heartbeat stuck-ceiling; track the last real worker reply separately. In the timeout arm, check whether the reply already completed before throwing. | | 2.6 | WRK-002, WRK-006 | The pipe-connect wait races `Process.WaitForExitAsync`. On early exit, report the exit code and stderr tail. Launch-failure cleanup wraps `Kill` in try/catch and always disposes the pipe. | | 2.7 | WRK-003 | Include the outbound enqueue in the command deadline. | | 2.8 | WRK-005 | Use `TimeProvider` / `Stopwatch` monotonic time for heartbeat staleness. | | 2.9 | WRK-008, SES-007 | Guard `EventReceived` against re-creating a removed session entry (check a removed flag, or remove under the same lock). `Unregister` purges the session's item registrations. | | 2.10 | WRK-009 | Orphan cleanup kills only workers whose command line or pipe name carries a gateway PID that is no longer alive. | | 2.11 | MXA-003, WIP-007, WIP-009 | Cover the alarm poll join and handler dispose with the shutdown timeout. The watchdog ignores `ShuttingDown`. Keep a pipe read outstanding, or a parent-PID check, during MXAccess startup, and put a timeout on the hello read. | **Verify:** gateway build + `Session*`, `WorkerClient*`, `GatewayEndToEndFakeWorkerSmokeTests`. Worker items (2.11) also need the windev x86 build and Worker.Tests. **High findings filed separately:** - [ ] #247 SES-001 - [ ] #248 DSH-002 --- Source: `code-reviews/2026-12-02-perf-bugs/README.md` and `code-reviews/2026-12-02-perf-bugs/PLAN.md` (commit `f200bda6` on local branch `docs/review-2026-12-02-perf-bugs`, not yet pushed). Reviewed at `54367e74`.
dohertj2 added the area:gatewayarea:workerpriority:p1type:review-finding labels 2026-12-02 16:07:38 -05:00
Author
Owner

Decision (2026-12-03, recorded as D7 in code-reviews/2026-12-02-perf-bugs/PLAN.md): keepalive defaults: server pings after 60 s idle with a 10 s timeout and permits client pings every 30 s, including with no active call; all configurable under MxGateway:*.

Decision (2026-12-03, recorded as D7 in `code-reviews/2026-12-02-perf-bugs/PLAN.md`): keepalive defaults: server pings after 60 s idle with a 10 s timeout and permits client pings every 30 s, including with no active call; all configurable under `MxGateway:*`.
Author
Owner

Merged to main at 68043411 (pushed 2026-12-03). Gateway suite 1610 passed / 0 failed (macOS); windev worker CI 836 passed / 0 failed on that SHA.

All rows 2.1–2.11 done. Server keepalive: MxGateway:Protocol:Http2KeepAlivePingDelaySeconds (60) / Http2KeepAlivePingTimeoutSeconds (10); Kestrel has no min-client-ping setting and never GOAWAYs on ping rate. Behaviour change: orphan cleanup skips (logs) processes whose path and command line are both unreadable. WRK-002 stderr tail split out to #259.

Merged to `main` at `68043411` (pushed 2026-12-03). Gateway suite 1610 passed / 0 failed (macOS); windev worker CI 836 passed / 0 failed on that SHA. All rows 2.1–2.11 done. Server keepalive: `MxGateway:Protocol:Http2KeepAlivePingDelaySeconds` (60) / `Http2KeepAlivePingTimeoutSeconds` (10); Kestrel has no min-client-ping setting and never GOAWAYs on ping rate. Behaviour change: orphan cleanup skips (logs) processes whose path and command line are both unreadable. WRK-002 stderr tail split out to #259.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/mxaccessgw#253