Skip to content

fix(client): honor AbortSignal on in-flight websocket operations - #7440

Closed
Solaris-star wants to merge 1 commit into
trpc:mainfrom
Solaris-star:fix/7439-wslink-abort-signal
Closed

Solaris-star wants to merge 1 commit into
trpc:mainfrom
Solaris-star:fix/7439-wslink-abort-signal

Conversation

@Solaris-star

@Solaris-star Solaris-star commented Jul 21, 2026 •

Copy link
Copy Markdown

Closes #7439

🎯 Changes

Bug fix for wsLink / wsClient.request().

AbortSignal was plumbed into request() and teardown already called signal?.removeEventListener('abort', abort), but there was no matching addEventListener. Aborting the caller's controller therefore never cancelled in-flight WS queries/mutations/subscriptions.

This PR:

  • if signal is already aborted β†’ call abort() immediately
  • otherwise β†’ signal.addEventListener('abort', abort, { once: true })
  • keep existing removeEventListener + subscription.stop cleanup

βœ… Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

(Happy to add a focused unit/integration test for signal abort if maintainers want a preferred harness location.)

Summary by CodeRabbit

  • Bug Fixes
    • WebSocket requests now properly stop when their associated cancellation signal is triggered.
    • Requests are canceled immediately when the signal has already been aborted.

request() already removed an abort listener on teardown, but never
registered addEventListener. Wire the signal so abort() cancels the
pending batchSend (and subscription cleanup still runs on unsubscribe).

Closes #7439

Signed-off-by: Solaris-star <[email protected]>
@Solaris-star
Solaris-star requested a review from a team as a code owner July 21, 2026 03:09
@vercel

vercel Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
next-prisma-starter Ready Ready Preview Jul 21, 2026 3:10am
og-image Ready Ready Preview, Comment Jul 21, 2026 3:10am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

πŸ“ Walkthrough

Walkthrough

WsClient.request now connects caller-provided AbortSignal events to internal WebSocket request cancellation, including signals already aborted before request setup.

Changes

WebSocket request cancellation

Layer / File(s) Summary
Wire AbortSignal into request cleanup
packages/client/src/links/wsLink/wsClient/wsClient.ts
Registers a one-time abort listener for active signals, immediately aborts already-aborted signals, and preserves listener cleanup during teardown.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

  • trpc/trpc#7434 β€” Updates the same WsClient.request AbortSignal and WebSocket lifecycle handling.
πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Linked Issues check βœ… Passed The code change registers the abort listener, handles pre-aborted signals, and keeps cleanup, matching #7439.
Out of Scope Changes check βœ… Passed The PR stays focused on wsClient AbortSignal wiring and does not introduce unrelated changes.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check βœ… Passed The title clearly summarizes the main change: honoring AbortSignal for in-flight websocket operations.
Description check βœ… Passed The description matches the template with the issue reference, changes section, and checklist.
✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trpc/client

npm i https://pkg.pr.new/@trpc/client@7440

@trpc/next

npm i https://pkg.pr.new/@trpc/next@7440

@trpc/openapi

npm i https://pkg.pr.new/@trpc/openapi@7440

@trpc/react-query

npm i https://pkg.pr.new/@trpc/react-query@7440

@trpc/server

npm i https://pkg.pr.new/@trpc/server@7440

@trpc/tanstack-react-query

npm i https://pkg.pr.new/@trpc/tanstack-react-query@7440

@trpc/upgrade

npm i https://pkg.pr.new/@trpc/upgrade@7440

commit: 7468715

@Solaris-star Solaris-star changed the title fix(wsLink): honor AbortSignal on in-flight websocket operations fix(client): honor AbortSignal on in-flight websocket operations Jul 24, 2026
@Solaris-star Solaris-star closed this by deleting the head repository Aug 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 13, 2026

This branch was successfully deployed

5 active deployments
Preview – www β€” 74687155 Deployed Jul 21, 2026 by vercel[bot]
Preview – next-prisma-starter β€” 74687155 Deployed Jul 21, 2026 by vercel[bot]
Preview – trpc-next-app-dir β€” 74687155 Deployed Jul 21, 2026 by vercel[bot]
Preview – examples-todomvc β€” 74687155 Deployed Jul 21, 2026 by vercel[bot]
Preview – og-image β€” 74687155 Deployed Jul 21, 2026 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wsLink: AbortSignal on operations is ignored β€” abort does not cancel in-flight requests or subscriptions

1 participant