Skip to content

Conversation

@ncoquelet
Copy link

@ncoquelet ncoquelet commented Nov 28, 2025

Problem

Fixes #3761

When a WebSocket connection closes or enters a CLOSING state during an unsubscribe operation, the _updateSubscriptions() of the connection method of the connection enters an infinite loop. The issue occurs because isCurrentConnectionStillActive() only checks if the connection generation has changed, but doesn't verify the actual WebSocket readyState.

Error scenario:

accountUnsubscribe error: Tried to call a JSON-RPC method accountUnsubscribe 
but the socket was not CONNECTING or OPEN (readyState was 2)

When this error is caught, the code retries the unsubscribe operation indefinitely because the connection generation hasn't changed, even though the socket is no longer usable.

Solution

Update isCurrentConnectionStillActive() to also check the WebSocket's readyState, ensuring it's in a valid state (CONNECTING or OPEN) before considering the connection active.

Changes:

  • Exposed readyState in RpcWebSocketClient
  • Modified isCurrentConnectionStillActive() check in _updateSubscriptions()
  • Added test cases to verify the fix prevents infinite loops on socket state errors

Testing

Added two new test cases that simulate:

  1. Socket in CLOSING state during unsubscribe
  2. Socket in CLOSED state during unsubscribe

Both tests verify that _updateSubscriptions() doesn't enter an infinite loop and properly detects disconnected sockets.

Note: Local unit tests are not running properly (documentation appears outdated). Waiting for GitHub Actions CI to validate the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[URGENT] Infinite loop in Connection._updateSubscriptions()

1 participant