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
WebSocket adapter: a subscription's cleanup error after the client stops it never reaches onError #7887
🤖 When a client stops a WebSocket subscription (unsubscribe(), abort, or disconnect), the subscription's cleanup can throw: an observable teardown, or a generator's finally. That error is dropped. The server's onError isn't called, and nothing is logged.
constt=initTRPC.create();constrouter=t.router({onTick: t.procedure.subscription(()=>observable<number>((emit)=>{emit.next(1);return()=>{thrownewError('teardown');// a bug in cleanup code};}),),});applyWSSHandler({ wss, router,onError: ({ error })=>console.error(error)});// client, over wsLinkconstsub=client.onTick.subscribe(undefined,{onData(){}});sub.unsubscribe();// the teardown throws on the server; onError is never called
Expected:onError is called with the cleanup error, as it is when the subscription completes on its own.
Actual:onError isn't called. This also happens with an async function* whose finally throws once the stop wakes it, and when the client disconnects.
Root cause:ws.ts:363-371 races the pending iterator.next() against the stop and breaks on 'abort'. The cleanup error rejects that next() after the race is decided, and nothing handles the rejection.
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(server): report a ws subscription's cleanup error after the clien…
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.