Fix infinite loop when WebSocket errors during unsubscribe #3765
+115
−1
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
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 becauseisCurrentConnectionStillActive()only checks if the connection generation has changed, but doesn't verify the actual WebSocketreadyState.Error scenario:
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'sreadyState, ensuring it's in a valid state (CONNECTING or OPEN) before considering the connection active.Changes:
readyStatein RpcWebSocketClientisCurrentConnectionStillActive()check in_updateSubscriptions()Testing
Added two new test cases that simulate:
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.