-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(socket): recover from stale disconnected socket to prevent permanent "Connecting..." #2487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,6 +161,13 @@ class SocketService { | |
| } else if (!this.socket.disconnected) { | ||
| // Socket is connecting, wait for it | ||
| return; | ||
| } else { | ||
| // Stale disconnected socket instance for the same token. | ||
| // Drop it so this connect attempt can create a fresh socket; | ||
| // otherwise the async stale-invocation guard below (`|| this.socket`) | ||
| // returns early and leaves connectivity stuck at "connecting". | ||
| this.socket = null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [major] The stale socket is abandoned via null-assignment rather than shut down cleanly. Two problems:
Suggested fix: } else {
// Stale disconnected socket, same token. Shut it down before clearing
// to cancel any queued socket.io reconnect timers and avoid stale Redux
// dispatches from the abandoned socket's event handlers.
this.socket.disconnect();
this.socket = null;
this.mcpTransport = null;
this.listenerMap.clear();
this.pendingListeners = [];
}This matches what |
||
| this.mcpTransport = null; | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor] The test validates that
io()is called twice (new socket created) which is the core regression being guarded. A small addition would increase confidence that the reconnect path actually executes past the stale-socket guard rather than taking some other code path:Not a blocker, but would catch a regression where
io()gets called for an unrelated reason.