fix(websocket): increment failover counter on externally-closed connections#704
Draft
cl-efornaciari wants to merge 1 commit intomainfrom
Draft
fix(websocket): increment failover counter on externally-closed connections#704cl-efornaciari wants to merge 1 commit intomainfrom
cl-efornaciari wants to merge 1 commit intomainfrom
Conversation
…ctions When a WebSocket connection is closed externally (e.g., provider drops with code 1005), streamHandler now detects this and increments the failover counter. Previously, only open-but-unresponsive connections incremented the counter, causing externally-closed connections to reconnect to the same failing endpoint indefinitely. The fix adds an `else if` branch after the existing connectionUnresponsive check that detects when connectionClosed is true with an existing wsConnection, indicating the server dropped the connection between streamHandler cycles. Tests are adjusted from bug-demonstration (asserting counter === 0) to fix-validation (asserting counter > 0 and EA recovery after server stabilizes).
Contributor
NPM Publishing labels 🏷️🛑 This PR needs labels to indicate how to increase the current package version in the automated workflows. Please add one of the following labels: |
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.
Summary
else ifbranch inWebSocketTransport.streamHandlerthat detects when a connection was closed externally (e.g., provider drops with code 1005) and incrementsstreamHandlerInvocationsWithNoConnection, enablingwsSelectUrlto try alternate URLs.Root Cause
When a provider drops a WebSocket connection with close code 1005,
streamHandlerfindsconnectionClosed == trueand immediately reconnects, resettingconnectionOpenedAt. On the next cycle,timeSinceConnectionOpenedis only ~5s (oneBACKGROUND_EXECUTE_MS_WSinterval), which is belowWS_SUBSCRIPTION_UNRESPONSIVE_TTL(default 120s). SinceconnectionUnresponsivenever becomes true, the failover counter stays at 0 and the EA reconnects to the same failing endpoint forever.Fix
After the existing
connectionUnresponsivecheck, add a second path that detects whenconnectionClosed && this.wsConnection(connection was closed externally, not by the framework) and increments the failover counter. Theelse ifprevents double-counting when both conditions are true.Related
Test plan
Made with Cursor