Skip to content

fix(signal): don't log a requested signal close as a read error - #2192

Merged
1egoman merged 1 commit into
livekit:mainfrom
ninglinLiu:fix/signal-read-error-on-requested-close
Oct 26, 2026
Merged

1egoman merged 1 commit into
livekit:mainfrom
ninglinLiu:fix/signal-read-error-on-requested-close

Conversation

@ninglinLiu

Copy link
Copy Markdown
Contributor

Fixes #2191

Problem

SignalClient.startReadingLoop logged error reading from signal stream at error level before calling handleOnClose. handleOnClose already recognizes a close the client caused itself, or one from a replaced transport (transportFailed doesn't move the lifecycle), and logs that at debug level. The error line had already been written by then. So every normal disconnect() that ended with a rejected read() (for example WS 1006) produced a false error in the console and in error monitoring.

Change

The reading loop now passes the read error to handleOnClose. It is logged at error level only when the lifecycle accepts the transport failure, which means the loss was unexpected. When the close is ignored, the error is attached to the existing debug ignoring transport close in state … log, so it stays visible for debugging. Nothing else about close handling changes.

Tests

New Signal stream read errors tests in SignalClient.test.ts:

  • an unexpected read failure while connected is still logged at error level and reported through onClose
  • a read failure after close() logs no error, logs at debug level with the error attached, and does not call onClose. This test fails on main.

vitest run src/api/SignalClient.test.ts (60 passed), tsc --noEmit, eslint and prettier pass. Includes a patch changeset.

This PR was prepared with AI assistance and reviewed/tested by the author.

@changeset-bot

changeset-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8c606df

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

@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 potential issue.

Devin Review

Comment thread src/api/SignalClient.ts
await this.handleOnClose('error in reading loop', attemptId);
// only an unexpected loss is an error: a read that fails because we closed the socket
// ourselves (or it was replaced) is logged at debug level by handleOnClose
await this.handleOnClose('error in reading loop', attemptId, undefined, e);

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.

🟡 Abnormal signal drops lose error logs

When an abnormal socket close precedes the reader rejection, handleOnClose accepts the close and ignores the subsequent read error. The close handler logs only at info level, so error monitoring misses the unexpected drop.

Learn more

A WebSocketStream exposes both a closed promise and a readable stream. For an abnormal close, its close-event listener settles closed and its readable handler rejects the pending read. The close handler can reach handleOnClose first and move the lifecycle offline. The reader catch then passes the same unexpected failure here, but the offline lifecycle makes transportFailed a no-op. Its error is logged only at debug, while the accepted close logged at info; the old reader catch logged the error regardless of event order.

Example: A connected browser receives a server-side abnormal close (1006). The socket's closed handler marks the client offline. The pending read() then rejects with WS closed unexpectedly with code 1006, but no error-level log records the failure.

Recommended fix: Preserve error-level reporting for an abnormal live-transport close regardless of which notification arrives first, while suppressing it for explicit close() and replaced attempts. Exercise the actual WebSocketStream close/read order in a regression test rather than calling startReadingLoop with a synthetic reader after the connection state is chosen.

Devin Review


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

@1egoman 1egoman 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.

I think this makes sense to me - thanks for the contribution @ninglinLiu!

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.

error reading from signal stream (WS 1006) is logged at error level on every normal call end (2.23.0)

2 participants