Repository navigation
fix(runtime): stop a stalled tick from forgiving banked missed probes (STA-3320) - #12841
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 88d7da61-57bb-4b7d-8cf2-e972372a7fb5
📥 Commits
Reviewing files that changed from the base of the PR and between 211b2d1 and 83f2f75cc0f45b09c6af86deaaf6f5df1eddd4cb.
📒 Files selected for processing (11)
src/main/runtime/rpc/remote-runtime-server-heartbeat-missed-probe-tolerance.test.tssrc/main/runtime/rpc/remote-runtime-server-heartbeat.test.tssrc/main/runtime/rpc/remote-runtime-server-heartbeat.tssrc/main/runtime/rpc/ws-transport-accept-order.test.tssrc/main/runtime/rpc/ws-transport-transient-packet-loss.test.tssrc/main/runtime/rpc/ws-transport.tssrc/renderer/src/web/web-runtime-client.test.tssrc/renderer/src/web/web-runtime-client.tssrc/shared/reconnect-jitter.test.tssrc/shared/reconnect-jitter.tssrc/shared/remote-runtime-shared-control-state.ts
| @@ -21,7 +21,7 @@ type WebSocketMessageHandler = { | |||
| ): void | |||
| }['bivarianceHack'] | |||
|
|
|||
| // Why: mobile clients background-suspend sockets with no TCP FIN, leaving half-opens that otherwise only the OS keepalive (~2h) reaps; a 15s ping/pong sweep bounds that to ~30s (clients auto-pong per RFC 6455). | |||
| // Why: mobile clients background-suspend sockets with no TCP FIN, leaving half-opens that otherwise only the OS keepalive (~2h) reaps; a 15s ping/pong sweep bounds that to ~60s (clients auto-pong per RFC 6455), since a reap needs consecutive unanswered probes rather than one (STA-3320). | |||
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the heartbeat timing bound.
The socket is terminated on the third missed check at approximately 45 seconds after the last successful sweep. The ~60s value adds one interval that the implementation does not wait.
Proposed fix
-// Why: mobile clients background-suspend sockets with no TCP FIN, leaving half-opens that otherwise only the OS keepalive (~2h) reaps; a 15s ping/pong sweep bounds that to ~60s (clients auto-pong per RFC 6455), since a reap needs consecutive unanswered probes rather than one (STA-3320).
+// Why: mobile clients background-suspend sockets with no TCP FIN, leaving half-opens that otherwise only the OS keepalive (~2h) reaps; three consecutive missed 15s ping/pong checks bound reaping to ~45s (STA-3320).📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Why: mobile clients background-suspend sockets with no TCP FIN, leaving half-opens that otherwise only the OS keepalive (~2h) reaps; a 15s ping/pong sweep bounds that to ~60s (clients auto-pong per RFC 6455), since a reap needs consecutive unanswered probes rather than one (STA-3320). | |
| // Why: mobile clients background-suspend sockets with no TCP FIN, leaving half-opens that otherwise only the OS keepalive (~2h) reaps; three consecutive missed 15s ping/pong checks bound reaping to ~45s (STA-3320). |
Post-merge review of #12790 demonstrated a real leak: the resume-from-pause pardon cleared banked misses outright, so a host whose sweep stalls once every three ticks reset the budget forever and a dead socket was never reaped. The reviewer ran 300 sweeps against a permanently dead peer with a >1.5x gap every third tick and observed zero terminate() calls. Pre-#12790 that required a stall on *every* tick; the counter widened the pathological window 3x, and the failure mode is permanent non-reaping — the MAX_WS_CONNECTIONS leak the reaper exists to prevent. A stalled tick now charges no miss, which is all the original rationale needed (the client had no chance to answer that probe), but no longer forgives the misses already banked. A live client still clears its own count by answering the probe that is still sent on the stalled tick. The tolerance test's pause case is rewritten to assert the new contract rather than the old forgive-everything one, and a new test pins the leak directly: a host stalling every third tick must still reap a dead socket.
83f2f75 to
afd93d9
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
…stablyai#12841) Post-merge review of stablyai#12790 demonstrated a real leak: the resume-from-pause pardon cleared banked misses outright, so a host whose sweep stalls once every three ticks reset the budget forever and a dead socket was never reaped. The reviewer ran 300 sweeps against a permanently dead peer with a >1.5x gap every third tick and observed zero terminate() calls. Pre-stablyai#12790 that required a stall on *every* tick; the counter widened the pathological window 3x, and the failure mode is permanent non-reaping — the MAX_WS_CONNECTIONS leak the reaper exists to prevent. A stalled tick now charges no miss, which is all the original rationale needed (the client had no chance to answer that probe), but no longer forgives the misses already banked. A live client still clears its own count by answering the probe that is still sent on the stalled tick. The tolerance test's pause case is rewritten to assert the new contract rather than the old forgive-everything one, and a new test pins the leak directly: a host stalling every third tick must still reap a dead socket. Co-authored-by: Jinwoo-H <[email protected]>
Fix-forward on #12790, from its post-merge adversarial review. That review's verdict was SOUND — do not revert, and this addresses the one real defect it demonstrated.
The defect
#12790's resume-from-pause pardon cleared banked misses outright. So a host whose sweep stalls once every three ticks reset the budget forever and a dead socket was never reaped.
Demonstrated by the reviewer: a permanently dead peer, with a
> intervalMs * 1.5gap every third tick, ran 300 sweeps (50 simulated minutes) with zeroterminate()calls. Boundary confirmed — a stall every 4th tick still reaps; every 3rd tick never does.Pre-#12790 this required a stall on every tick to prevent a reap. The consecutive counter widened the pathological window 3×, and the failure mode is permanent non-reaping — exactly the
MAX_WS_CONNECTIONS = 128leak the reaper exists to prevent.The fix
A stalled tick now charges no miss but forgives nothing.
That is all the original rationale ever needed: a delayed tick cannot infer that clients missed a probe they had no chance to answer, so it must not charge one. Clearing the count as well was over-generous — those earlier misses were banked while the server was running normally, so they are real evidence.
A live client still clears its own count by answering the probe that is still sent on the stalled tick, so a genuine suspend costs a healthy peer nothing.
Verification
The tolerance test's pause case is rewritten to assert the new contract, not weakened — it now pins both halves: the suspend itself costs the socket nothing, and the pre-suspend evidence survives so the next unanswered probe completes the budget. Renamed accordingly (
charges no miss for a paused tick but keeps the ones already banked).A new test pins the leak directly: a host stalling every third tick must still reap a dead socket.
Mutation-proven: forcing
stalledTicktofalsefails the pause test; restored by re-applying the edit, nevergit checkout.Suites:
src/main/runtime/rpc/— 124 files, 1220 passing. Includes the pre-existing real-socket half-open reap test (ws-transport.test.ts, kernel-level_socket.pause()), untouched and still green.Also corrects a stale comment in
ws-transport.test.tsthat still said "two consecutive ping ticks" — it has been four since #12790.Not addressed here
The review also noted that
elapsedMs < 0reads a wall clock (Date.now), so a backward NTP or VM-migration step grants a one-off pardon. Harmless in isolation now that a pardon no longer forgives banked misses, but it means the reaper's correctness still depends on a clock a user can change. Moving to a monotonic source is a separate change with its own suspend-semantics questions (CLOCK_MONOTONICexcludes suspend time,CLOCK_BOOTTIMEincludes it), so it should not ride along with this.The review's other observation — that a flapping device can now hold 2-3 connection slots instead of 1-2, because the client's own 25s watchdog redials while the server holds the stale socket up to 60s — is by design (
hasOtherConnections) and absorbed by the 128-slot budget, but it is worth its own look if slot pressure is ever reported.