Repository navigation
fix(signal): don't log a requested signal close as a read error - #2192
Conversation
🦋 Changeset detectedLatest commit: 8c606df The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
| 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); |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
I think this makes sense to me - thanks for the contribution @ninglinLiu!
Fixes #2191
Problem
SignalClient.startReadingLooploggederror reading from signal streamat error level before callinghandleOnClose.handleOnClosealready recognizes a close the client caused itself, or one from a replaced transport (transportFaileddoesn't move the lifecycle), and logs that at debug level. The error line had already been written by then. So every normaldisconnect()that ended with a rejectedread()(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 debugignoring transport close in state …log, so it stays visible for debugging. Nothing else about close handling changes.Tests
New
Signal stream read errorstests inSignalClient.test.ts:onCloseclose()logs no error, logs at debug level with the error attached, and does not callonClose. This test fails onmain.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.