Skip to content

fix: catch unhandled ws signal errors - #2065

Merged
lukasIO merged 9 commits into
mainfrom
lukas/catch-unhandled-ws-rej
Aug 26, 2026
Merged

fix: catch unhandled ws signal errors#2065
lukasIO merged 9 commits into
mainfrom
lukas/catch-unhandled-ws-rej

Conversation

@lukasIO

@lukasIO lukasIO commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

closes #2062

@changeset-bot

changeset-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b14d3ba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
livekit-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 110.56 KB (+0.09% 🔺)
dist/livekit-client.umd.js 119.73 KB (+0.12% 🔺)

devin-ai-integration[bot]

This comment was marked as resolved.

lukasIO and others added 5 commits August 25, 2026 09:11
…ent-sdk-js into lukas/catch-unhandled-ws-rej
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
devin-ai-integration[bot]

This comment was marked as resolved.

Comment thread src/api/WebSocketStream.ts Outdated

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View 1 additional finding in Devin Review. (Configure)

Open in Devin Review

Comment thread src/api/SignalClient.ts
Comment on lines +681 to 685
} catch (e) {
this.log.error(`error reading from signal stream`, { error: e });
await this.close(false, 'error in reading loop');
break;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Stale read loop can close the live connection

On any read error the loop calls close(false, ...), which tears down whatever this.ws currently is, with no check that the failing reader still owns it. When an earlier attempt's socket closes uncleanly after a newer attempt has installed a new this.ws, the stale loop closes the healthy new connection. handleOnClose guards this cross-attempt case with attemptId; the read loop does not.

Prompt for agents
The signal read loop in startReadingLoop (src/api/SignalClient.ts) now calls this.close(false, 'error in reading loop') on any read error. close() -> teardownTransport() unconditionally closes the current this.ws, but the read loop is not scoped to the connection attempt it belongs to. handleSignalConnected (around line 1207) starts the loop with connection.readable.getReader() but does not pass attemptId, whereas handleOnClose guards transport teardown with attemptId to avoid tearing down a transport that a newer attempt has since installed. Because teardownTransport can return before the old socket is actually CLOSED (Promise.race with MAX_WS_CLOSE_TIME around line 729-735), an old reader can reject after this.ws has been replaced, and the old loop's close(false) would then tear down the new, healthy connection. Consider making the read loop attempt-aware (pass attemptId into startReadingLoop and guard the close call with it, similar to handleOnClose), or route the read-error teardown through handleOnClose so the existing attemptId guard applies.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@lukasIO
lukasIO merged commit 9bfade5 into main Aug 26, 2026
6 checks passed
@lukasIO
lukasIO deleted the lukas/catch-unhandled-ws-rej branch August 26, 2026 09:48
@github-actions github-actions Bot mentioned this pull request Aug 26, 2026
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.

Unhandled promise rejection with raw DOM Event on post-connect WebSocket error

2 participants