fix(browser): handle stale extension WebSocket on reconnect#18698
Closed
codexGW wants to merge 1 commit intoopenclaw:mainfrom
Closed
fix(browser): handle stale extension WebSocket on reconnect#18698codexGW wants to merge 1 commit intoopenclaw:mainfrom
codexGW wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Contributor
Author
|
Note: PR #15817 also touches this 409 path, but takes a different approach — it unconditionally replaces any existing extension socket (even if This PR is intentionally more conservative:
Both PRs are independent and non-conflicting in intent, but would need a merge conflict resolution if both land. |
The relay server rejects new extension connections with 409 when extensionWs is non-null, even if the underlying socket is already in CLOSING or CLOSED state. This commonly happens when a Manifest V3 service worker is killed and restarts — the old socket lingers in a stale state and blocks the fresh connection attempt. Two targeted fixes: 1. Only reject with 409 when the existing socket is actually OPEN. If it is stale (CLOSING/CLOSED), terminate it and accept the new connection. 2. Add an identity guard in the close handler so that a late-firing close event from a replaced socket does not wipe state belonging to the active connection.
21c2e68 to
5619b3f
Compare
18 tasks
Member
|
Closing as duplicate of #20688. If this is incorrect, please contact us. |
18 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The relay server rejects new extension connections with
409 Extension already connectedwhenextensionWsis non-null, even if the underlying socket is already inCLOSINGorCLOSEDstate.This commonly happens with Manifest V3 service workers — Chrome kills the worker after ~30s of inactivity, and when it restarts and attempts to reconnect, the old socket is still lingering in a half-closed state. The user sees a connection failure and has to manually toggle the extension.
Fix
Two small, targeted changes to
extension-relay.ts:Only reject with 409 when the existing socket is actually
OPEN. If the socket is stale (CLOSING/CLOSED), terminate it and accept the new connection.Add an identity guard in the close handler so that a late-firing
closeevent from a replaced socket does not wipe state belonging to the newer active connection.What this does NOT change
background.js)Testing
Tested by attaching the extension, restarting the gateway (simulating stale socket), and reconnecting — the extension now connects cleanly without requiring a manual toggle.
Greptile Summary
Fixes a reconnection issue in the Chrome extension relay where stale WebSocket connections (in
CLOSING/CLOSEDstate) prevented new extension connections from being established. The fix checks socket state before rejecting with 409, terminates stale sockets, and adds an identity guard in the close handler to prevent late-firing close events from wiping state of newer connections. This resolves the common Manifest V3 service worker scenario where Chrome kills the worker after ~30s inactivity, leaving lingering half-closed sockets.Confidence Score: 5/5
readyStatebefore rejection and preventing old close handlers from interfering with new connections via identity comparison. Both changes align with WebSocket best practices.Last reviewed commit: 21c2e68
(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!