You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
wsClient: reconnect errors are swallowed, and a throwing onClose or onError stops reconnects #7890
1. A connectionParams error on reconnect is never surfaced
lettoken: string|null='ok';constwsClient=createWSClient({
url,connectionParams: ()=>{if(!token)thrownewError('token refresh failed');return{ token };},});constclient=createTRPCClient<AppRouter>({links: [wsLink({client: wsClient})]});client.onTick.subscribe(undefined,{onConnectionStateChange: (s)=>console.log(s.state,s.error?.cause),});// later: token = null, and the server drops the connection
Expected: as on the first connect, the connection state goes to connecting with an Initialization error whose cause is the thrown error, and the client keeps retrying with backoff.
Actual: the error is dropped. The state flips between pending and connecting / "WebSocket closed" forever, and nothing ever shows token refresh failed.
Root cause:tryReconnect in wsClient.ts:302 wraps each attempt in a bare catch {} and retries. The first-connect path in open() (wsClient.ts:130-137) reports the same failure on connectionState.
2. A throwing onClose (or onError) stops reconnects
constwsClient=createWSClient({
url,onClose: ()=>{thrownewError('bug in my onClose');},});client.onTick.subscribe(undefined,{onData: console.log});// the server drops the connection
Expected: the subscription reconnects and resumes. The callback's error is still reported, for example as an uncaught exception.
Actual: the subscription never reconnects. With a throwing onError, the client hangs on the first failed connect, and even wsClient.close() never settles.
Root cause: the close and error listeners (wsClient.ts:373-397) call the user callback before this.reconnect(...), so a throw skips it. With ws (an EventEmitter), the throw also skips the other listeners for that event. One of these is asyncWsOpen's error listener, so the open promise never settles.
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.
Activity
fix(client): surface wsClient reconnect errors, and keep reconnecting…
github-actions commentedon Nov 5, 2026
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.