fix: prevent infinite loop in _updateSubscriptions when socket is closed#3783
Closed
babuClawd wants to merge 1 commit intosolana-foundation:maintenance/v1.xfrom
Closed
Conversation
When a WebSocket transitions to CLOSING/CLOSED state without triggering
a new generation, the unsubscribe call fails but isCurrentConnectionStillActive()
still returns true. This causes _updateSubscriptions to recursively retry
indefinitely, producing a storm of console.error messages and eventually
crashing the process.
Fix: check the WebSocket readyState before retrying. If the socket is no
longer OPEN, mark the subscription as 'unsubscribed' — the server-side
subscription is effectively dead anyway. When a new connection is
established, subscriptions will be re-evaluated.
Also removes a duplicate _setSubscription('unsubscribing') call.
Fixes solana-foundation#3761
Author
|
Closing in favor of #3778 which takes a more thorough approach — exposing |
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
When a WebSocket transitions to CLOSING/CLOSED state without triggering a new generation,
_updateSubscriptions()enters an infinite recursive loop (#3761).The flow:
subscribedstate and needs to be torn down_rpcWebSocket.call(unsubscribeMethod)fails because the socket is closed (readyState=2)isCurrentConnectionStillActive()returnstrue(generation counter unchanged)subscribed_updateSubscriptions()is called recursively → back to step 2This causes a storm of
accountUnsubscribe errorconsole messages and eventually crashes the process.Fix
1. Check WebSocket readyState before retrying:
If the socket is no longer
OPEN, mark the subscription asunsubscribedinstead of retrying. The server-side subscription is effectively dead — when a new connection is established, subscriptions will be re-evaluated through the normal reconnection path.2. Remove duplicate
_setSubscriptioncall:The
unsubscribingstate was being set twice in the same block (copy-paste artifact).Risk
Low. This is a defensive guard that only activates when the socket is already dead. Normal subscription/unsubscription flow is unaffected. The existing reconnection logic handles resubscription when a new connection is established.
Fixes #3761