Skip to content

wsLink: AbortSignal on operations is ignored — abort does not cancel in-flight requests or subscriptions #7439

Closed

Description

@tsushanth

Description

The WebSocket link does not honor the AbortSignal passed with an operation. Calling abort() on the signal has no effect on in-flight queries, mutations, or subscriptions sent through wsLink.

Repro

const controller = new AbortController();
const result = trpc.someQuery.query(undefined, { signal: controller.signal });
controller.abort(); // has no effect on the WS request

Contrast with httpSubscriptionLink which correctly tears down the subscription when the signal fires.

Root cause

wsClient.ts:235 calls signal?.removeEventListener('abort', abort) in the cleanup path — but there is no corresponding signal?.addEventListener('abort', ...) anywhere in the wsLink source. The abort listener was never registered; only the cleanup was scaffolded.

This appears to be an incomplete implementation from the v11 refactor (PR #6223) which plumbed signal into the request function but only wired the teardown half.

Verified via the current source — signal is received at lines ~186 and ~190, but only removeEventListener is called (line 235); no addEventListener call exists anywhere in the wsLink directory.

Expected behaviour

When the caller's AbortSignal fires:

  • In-flight queries/mutations: the pending request should be cancelled and the promise rejected with AbortError
  • Subscriptions: the subscription should be torn down

Possible fix

In the request() function, after the early-exit check for signal?.aborted, add:

signal?.addEventListener('abort', teardownFn, { once: true });

and ensure teardownFn removes the listener when the operation completes normally (which is what the existing removeEventListener call at line 235 already does — it just has no matching registration).

Activity

  1. added 2 commits that reference this issue on Jul 23, 2026
    68aced5
    962b73d
  2. added a commit that references this issue on Sep 12, 2026
    fa6a1fe
  3. added a commit that references this issue on Sep 18, 2026
    6d98da6
  4. trpc-bot commented on Oct 19, 2026

    @trpc-bot
    Collaborator

    🤖 Fixed by #7434 — wsLink now registers and cleans up the AbortSignal listener. Closing; please reopen with a repro if you still see this on the latest release.

  5. github-actions commented on Oct 21, 2026

    @github-actions
    Contributor

    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.

  6. locked as resolved and limited conversation to collaborators on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions