fix(gateway): prevent 1006 errors from race condition in WebSocket upgrade#43392
Conversation
Greptile SummaryThis PR correctly fixes a startup race condition in the WebSocket upgrade path by restructuring the initialization order in Changes:
Confidence Score: 5/5
Last reviewed commit: 68e4af2 |
2de203c to
c83771e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c83771e6a3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
68aacde to
aa42f9e
Compare
aa42f9e to
ed83da0
Compare
Attach upgrade handlers before HTTP server starts listening. Fixes openclaw#43381
ed83da0 to
0bca6d3
Compare
|
Merged via squash.
Thanks @dalefrieswthat! |
…grade (openclaw#43392) Merged via squash. Prepared head SHA: 0bca6d3 Co-authored-by: dalefrieswthat <176454532+dalefrieswthat@users.noreply.github.com> Co-authored-by: grp06 <1573959+grp06@users.noreply.github.com> Reviewed-by: @grp06
…grade (openclaw#43392) Merged via squash. Prepared head SHA: 0bca6d3 Co-authored-by: dalefrieswthat <176454532+dalefrieswthat@users.noreply.github.com> Co-authored-by: grp06 <1573959+grp06@users.noreply.github.com> Reviewed-by: @grp06
…grade (openclaw#43392) Merged via squash. Prepared head SHA: 0bca6d3 Co-authored-by: dalefrieswthat <176454532+dalefrieswthat@users.noreply.github.com> Co-authored-by: grp06 <1573959+grp06@users.noreply.github.com> Reviewed-by: @grp06
…grade (openclaw#43392) Merged via squash. Prepared head SHA: 0bca6d3 Co-authored-by: dalefrieswthat <176454532+dalefrieswthat@users.noreply.github.com> Co-authored-by: grp06 <1573959+grp06@users.noreply.github.com> Reviewed-by: @grp06
…grade (openclaw#43392) Merged via squash. Prepared head SHA: 0bca6d3 Co-authored-by: dalefrieswthat <176454532+dalefrieswthat@users.noreply.github.com> Co-authored-by: grp06 <1573959+grp06@users.noreply.github.com> Reviewed-by: @grp06
…grade (openclaw#43392) Merged via squash. Prepared head SHA: 0bca6d3 Co-authored-by: dalefrieswthat <176454532+dalefrieswthat@users.noreply.github.com> Co-authored-by: grp06 <1573959+grp06@users.noreply.github.com> Reviewed-by: @grp06
…grade (openclaw#43392) Merged via squash. Prepared head SHA: 0bca6d3 Co-authored-by: dalefrieswthat <176454532+dalefrieswthat@users.noreply.github.com> Co-authored-by: grp06 <1573959+grp06@users.noreply.github.com> Reviewed-by: @grp06
Summary
Fix race condition where WebSocket connections could fail with 1006 (abnormal closure) because the upgrade handler was attached after the HTTP server started listening.
Root cause: The gateway started listening for HTTP connections before the WebSocket upgrade handler was attached. During this window, any incoming WebSocket connection would be dropped (socket destroyed) without a proper close frame, causing client-side 1006 errors.
Changes:
WebSocketServerand attach upgrade handlers before the HTTP servers start listeningChange Type
Scope
Linked Issue/PR
User-visible / Behavior Changes
Before:
gateway healthcould intermittently fail with WebSocket 1006, especially immediately after gateway startup.After: WebSocket connections are properly handled from the moment the gateway starts listening. The 1006 error message now includes troubleshooting hints when it does occur.
Security Impact
Repro + Verification
pnpm openclaw gateway run --port 18889 --bind loopback --auth token --token test --allow-unconfiguredpnpm openclaw gateway health --url ws://127.0.0.1:18889 --token testCompatibility / Migration