fix(client): stop WebSocket errors from crashing the process in RPCLink - #2111
Merged
Merged
Conversation
`ws` throws when an `error` event has no listener, and the WebSocket link transport only listened for `open`, `message` and `close`. A refused connection (including every reconnect attempt while the server is down) or a malformed frame from the server crashed the client process. The transport now absorbs `error`; the `close` event that always follows rejects pending calls or drives the reconnect path.
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Absorb WebSocket
errorevents —WebSocketLinkTransportnow registers a no-operrorlistener so EventEmitter-based sockets likewsdon't throw an uncaughterrorand crash the process; thecloseevent that follows rejects pending calls or drives reconnection (packages/client/src/adapters/websocket/transport.ts:238). - Regression tests against a real
wsserver/client — cover a refused connection rejecting withWebSocket closed (code 1006: ), a refused-then-recovered attempt reconnecting withmaxAttemptsemantics, and a malformed server frame (0xC1 0x00, RSV1 set) rejecting pending calls (packages/client/src/adapters/websocket/rpc-link.test.ts). ws/@types/wsdevDependencies — added to@orpc/clientfor those tests (packages/client/package.json).
I verified the tests fail without the fix (2 of 3 with ws tests error on uncaught ECONNREFUSED / RangeError: Invalid WebSocket frame: RSV1 must be clear), that pnpm --filter @orpc/client type:check and the 27-test file pass, and that ws@8.21.3's client error paths (receiverOnError, senderOnError) always drive the socket toward close, so settling through close is sound. No action needed.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/bun
@orpc/client
@orpc/cloudflare
@orpc/contract
@orpc/experimental-effect
@orpc/evlog
@orpc/hibernation
@orpc/json-schema
@orpc/experimental-lock
@orpc/experimental-msw
@orpc/nest
@orpc/next
@orpc/node
@orpc/openapi
@orpc/opentelemetry
@orpc/pinia-colada
@orpc/pino
@orpc/publisher
@orpc/ratelimit
@orpc/server
@orpc/shared
@orpc/swr
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/zod
commit: |
Contributor
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.

A client using the WebSocket
RPCLinkwith Node'swslibrary no longer crashes when the socket emitserror.wsthrows whenerrorhas no listener, and the link transport only listened foropen,messageandclose, so a refused connection or a malformed frame from the server took the whole client process down. The transport now absorbserror, and thecloseevent that always follows rejects pending calls or drives reconnection. This is the client-side counterpart to #2108.Fixes
WebSocket closed (code 1006: )instead of crashing and leaving the call hanging.reconnectenabled, refused attempts while the server is down go through the normal retry path (includingmaxAttemptand proactiveonClosereconnects) instead of crashing on every attempt.RangeError.Testing
wsserver and client cover a refused connection, reconnecting after one, and a malformed server frame. Run alone without the fix, each exits 1 on the uncaught error.wsand@types/wsare now devDependencies of@orpc/client.