VAPI-3808 VAPI-3804 fix(signaling): classify 409 handshake rejection distinctly from 403 - #19
Merged
Conversation
… from 403 The JS SDK (Bandwidth/javascript-brtc-sdk#17) fixed a reconnect storm caused by unlimited auto-reconnect treating a 409 (another device holds the endpoint) as retryable. The Swift SignalingClient has no auto-reconnect at all, so that storm can't happen here, but it also gave the app no way to tell a 403 (bad token) or 409 (endpoint occupied) apart from any other WebSocket drop — both non-retryable conditions worth surfacing distinctly. Capture the rejected handshake's HTTP status via WebSocketProtocol.response, add BandwidthRTCError.endpointOccupied, and thread the classification through the "close" event to a new BandwidthRTCClient.onDisconnected callback. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
dhelms-bw
approved these changes
Aug 20, 2026
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
javascript-brtc-sdk#17 fixed a reconnect storm in the JS SDK: its
Signalingclient is built with unlimited auto-reconnect, and only treated HTTP 403 as a fatal (non-retryable) handshake failure. A 409 — the gateway rejecting a connection because another device already holds that endpoint — was treated as retryable, causing rapid repeated reconnect attempts against a gateway correctly refusing the connection.The Swift
SignalingClienthas no built-in auto-reconnect at all (it's a rawURLSessionWebSocketTask, andconnect()already throws.alreadyConnectedif called while connected), so that specific storm can't happen here. But the SDK also gave callers no way to distinguish why the signaling WebSocket closed — a bad token (403), an endpoint already in use by another device (409), and any other drop all looked identical from the app's perspective.Change
WebSocketProtocolnow exposes the underlyingresponse: URLResponse?(available viaURLSessionWebSocketTaskafter a rejected handshake).SignalingClient.handleReceiveErrorreads the HTTP status of a rejected handshake and threads it through the"close"event as a smallWebSocketCloseInfopayload, logging distinctly for the known fatal cases (403/409).BandwidthRTCError.endpointOccupiedfor 409.BandwidthRTCClientdecodes the close reason and exposes a newonDisconnected: (BandwidthRTCError) -> Voidcallback, mapping 403 →.invalidToken, 409 →.endpointOccupied, otherwise.webSocketDisconnected— so an app that retriesconnect()on disconnect can tell these apart and avoid hammering the gateway on a non-retryable failure.Bumped
VERSIONto 1.0.7 per repo convention.Test plan
testCloseEventCarriesStatusCodeOnRejectedHandshake(SignalingClientTests),testCloseEventWith409ReportsEndpointOccupied,testCloseEventWith403ReportsInvalidToken,testCloseEventWithNoStatusCodeReportsWebSocketDisconnected(ResourceLifecycleTests)xcodebuild test -scheme BandwidthRTC -destination 'platform=iOS Simulator,name=iPhone 17'— 218/218 passed🤖 Generated with Claude Code