Repository navigation
fix(gateway): flush slow-consumer 1008 close frame before terminating socket - #147707
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 4:23 AM ET / 08:23 UTC (Revision 9). ClawSweeper reviewWhat this changesGive overloaded Gateway sockets one shared, bounded grace period to deliver their disconnect reason before forced termination, with regression coverage for shutdown and replacement sockets. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main and the latest release retain the premature termination sequence. The previous shutdown blocker is resolved, the refreshed files preserve the reviewed repair, and no actionable correctness defect remains. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway sends responses and events to connected apps and nodes over WebSockets. Its transport lifecycle handles overloaded connections and coordinates their retirement during shutdown. flowchart TD
A[Responses and events] --> B[Gateway delivery]
B --> C{Socket overloaded?}
C -->|No| D[Send to peer]
C -->|Yes| E[Retire delivery and request close]
F[Connection close or shutdown] --> E
E --> G[One deadline per socket]
G --> H[Peer closes or forced termination]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +26, Tests +167. Total +193 across 10 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Maintain one bounded close owner per physical socket while preserving immediate delivery retirement and eventual connection cleanup. Do we have a high-confidence way to reproduce the issue? Yes: exceeding the outbound buffer limit reaches immediate close-then-terminate on current main, and the ws implementation confirms premature socket destruction; this review did not execute a runtime reproduction. Is this the best way to solve the issue? Yes: reusing the existing one-second grace through a shared socket owner fixes the delivery window and shutdown interaction without adding configuration or competing deadlines. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e27efbd2ed47. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
3d5d102 to
651581a
Compare
08c4ac5 to
e7986f0
Compare
… socket Slow-consumer disconnect called socket.close(1008) immediately followed by socket.terminate() in the same tick, so the 1008 close frame was never flushed and peers observed 1006 (abnormal closure) instead. Delay terminate() by WEBSOCKET_CLOSE_GRACE_MS (1s, matching the existing server-close.ts pattern) so the close handshake completes before the TCP connection is destroyed. Closes openclaw#146419
5f778c7 to
8463962
Compare
8463962 to
024452c
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
* commit '069710f909f0a7158777d0fc0bf1eab84e20c699': (45 commits) refactor(infra): consolidate update campaign reset ownership (openclaw#146555) refactor: simplify Gateway health response parsing (openclaw#147834) fix: avoid Gateway stalls when renaming sessions (openclaw#147869) refactor(plugins): reuse worker optional-method validation (openclaw#147925) refactor(infra): remove unreachable firewall diagnostic fallback (openclaw#147882) fix(ui): open attached automations from session hovercards (openclaw#147749) refactor(reply): share usage-bar numeric coercion (openclaw#147863) fix(doctor): report warnings for keyed agent configs (openclaw#123058) perf(plugins): reuse complete registry comparisons (openclaw#147893) fix(workboard): await lifecycle sweep completion in tests (openclaw#147950) fix: reduce stalls when browsing large session inventories (openclaw#147911) refactor(onboard): share custom model definition (openclaw#147915) feat(ios): collapse completed chat work above replies (openclaw#148002) fix(voice-call): retain state runtime for deferred streams (openclaw#147689) test(qa): compare Telegram entities semantically (openclaw#147752) fix(plugins): preserve runtime scope for deferred CLI actions (openclaw#147688) test(qa): keep Slack progress marker visible (openclaw#147748) test(qa): finish channel picker prompts (openclaw#147730) test(tui): handle auth restriction prompt (openclaw#147729) fix(qa): retain onboarding prompts across redraw bursts (openclaw#147687) ...
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
|
@vincentkoc Thanks for fixing and merging! |
* commit 'a08cdc50bc049074ed7ad2db9e18e0ed3f5415ec': (81 commits) perf: reuse stateless plugin scope defaults (#148080) fix(gateway): flush slow-consumer 1008 close frame before terminating socket (#147707) fix: keep model catalogs loading during other session updates (#147878) fix: show queued external chat messages and their source (#147848) refactor(chat): share math label configuration (#148073) perf(ui): trim eager debug overlay icon payload (#147954) improve(logbook): sample batch frame metadata in SQLite (#147999) fix(ui): dismiss suggested task cards without waiting (#148021) fix(maturity): cover governance, interoperability, fleet, and state (#143528) chore(ui): restore core lint and startup budget checks (#148010) fix: chat startup loads unnecessary session setup text (#147973) perf: speed up fresh cloud worker activation (#147945) fix: recover PR preparation after committed merge conflicts (#148063) test(plugins): isolate ClawHub Docker fixture identity (#148074) fix(release): acknowledge ClawHub risk on moving installs (#148041) fix: restore context reads for installed official Discord and Slack plugins (#143341) fix: identify source capsule filesystem failures (#147778) fix(linux): keep Quick Chat widgets bound to their Gateway (#146049) refactor(infra): consolidate update campaign reset ownership (#146555) refactor: simplify Gateway health response parsing (#147834) ...
… socket (openclaw#147707) * fix(gateway): flush slow-consumer 1008 close frame before terminating socket Slow-consumer disconnect called socket.close(1008) immediately followed by socket.terminate() in the same tick, so the 1008 close frame was never flushed and peers observed 1006 (abnormal closure) instead. Delay terminate() by WEBSOCKET_CLOSE_GRACE_MS (1s, matching the existing server-close.ts pattern) so the close handshake completes before the TCP connection is destroyed. Closes openclaw#146419 * trigger CI re-run for flaky server-plugins test * fix(gateway): preserve slow-consumer close reasons
Closes #146419
What Problem This Solves
Slow-consumer shutdown queued a WebSocket 1008 close frame and then terminated the transport before the peer could reliably receive the policy reason. The direct-response and node-delivery paths had the same abrupt-close behavior, and the broadcast fallback could target a replacement socket through the mutable client reference.
Graceful-close ownership also needed to span lifecycle callers. An ordinary close could leave Gateway shutdown waiting on the WebSocket library's longer default, while a broadcast slow-consumer close followed by shutdown could create a second close frame and fallback for the same socket.
Solution
close()throws, terminate immediately while preventing duplicate fallback ownership.dropIfSlow.The one-second grace period is best effort: recoverable peers receive code 1008 with reason
slow consumer; permanently stalled transports are still terminated after the grace expires.Evidence
GatewayConnectionWork.drain()reproduced a secondclose()call before the repair; the regression now proves one close frame, one fallback owner, one termination, and bounded drain.024452cb28e4ae908eb9b689a97ee44114c4b0ee: 298 tests passed across the seven focused Gateway suites, including the read-only connection transport suite.72e1a23cc3fddd79ed809aaa076a4411f60033b7refreshes onto current main while preserving the exact reviewed ten-file patch ID.slow consumerfor broadcast, direct-response, and node-delivery peers; a deliberately stalled socket terminated after grace, ordinary-close shutdown remained bounded, and a replacement socket remained open.