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 link silently ignores the operation AbortSignal (removeEventListener with no matching addEventListener) #7431
An AbortSignal passed to a WebSocket operation (op.signal, exposed via the signal request option) is never wired to anything. Aborting the caller's signal does not cancel an in-flight request nor stop a subscription. This diverges from httpSubscriptionLink, which honors op.signal.
Root cause
packages/client/src/links/wsLink/wsClient/wsClient.ts: the request() teardown calls signal?.removeEventListener('abort', abort), but there is no matching signal.addEventListener('abort', ...) anywhere in the wsLink client directory (signal appears only at the destructure, the type, and the removeEventListener; no signal.aborted/throwIfAborted either). The removeEventListener removes a listener that was never added. The v11 refactor (PR #6223) plumbed signal into request() but only added the cleanup half.
Steps to reproduce
Subscribe over a WS link with an AbortController, then ac.abort(). Observed: no subscription.stop frame is sent and the subscription keeps running; an in-flight WS query/mutation is likewise not cancelled. Expected: abort tears the operation down (and sends subscription.stop for subscriptions).
Suggested fix
In request(), after obtaining abort, wire the signal: if signal?.aborted tear down immediately; else signal?.addEventListener('abort', <teardown>, { once: true }), where teardown calls abort(), sends subscription.stop for subscriptions, and completes the observer — mirroring the existing return-cleanup.
The WebSocket link ignoring the AbortSignal is an issue in the wsLink's subscription cleanup path. When the caller supplies an AbortSignal via the TRPCClient options or through the link context, the wsLink should register an abort event listener on that signal that triggers the unsubscribe flow. Currently, the wsLink only handles connection-level cleanup (on close/error) and per-call cleanup (when the observable is torn down), but the AbortSignal passed at call time is not wired into either path.
The fix needs to be in the wsLink's request or subscription function where the observable is created. The AbortSignal's abort event should call the same teardown function that fires when the observer unsubscribes or the WebSocket connection drops. This mirrors how the httpBatchLink handles AbortSignal: it passes the signal to fetch() directly. For wsLink, there is no equivalent automatic propagation, so the signal must be handled manually.
The affected code is in the wsLink implementation where it creates the observable for a subscription call. Adding opts.signal?.addEventListener('abort', teardown) before returning the observable and cleaning it up in the teardown itself would resolve the leak.
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
cschanhniem commentedon Jul 8, 2026
The WebSocket link ignoring the AbortSignal is an issue in the wsLink's subscription cleanup path. When the caller supplies an AbortSignal via the TRPCClient options or through the link context, the wsLink should register an
abortevent listener on that signal that triggers the unsubscribe flow. Currently, the wsLink only handles connection-level cleanup (on close/error) and per-call cleanup (when the observable is torn down), but the AbortSignal passed at call time is not wired into either path.The fix needs to be in the wsLink's
requestorsubscriptionfunction where the observable is created. The AbortSignal'sabortevent should call the same teardown function that fires when the observer unsubscribes or the WebSocket connection drops. This mirrors how the httpBatchLink handles AbortSignal: it passes the signal to fetch() directly. For wsLink, there is no equivalent automatic propagation, so the signal must be handled manually.The affected code is in the wsLink implementation where it creates the observable for a subscription call. Adding
opts.signal?.addEventListener('abort', teardown)before returning the observable and cleaning it up in the teardown itself would resolve the leak.fix(client): wire the operation AbortSignal in the WebSocket link
fix(client): wire the operation AbortSignal in the WebSocket link
fix(client): wire the operation AbortSignal in the WebSocket link (tr…
github-actions commentedon Sep 13, 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.
fix(client,server): wire AbortSignal in wsLink and delete stale clien…