Skip to content

fix(client): release completed HTTP request abort listeners - #7606

Merged
KATT merged 2 commits into
trpc:mainfrom
brennanbutler01:fix/dispose-http-abort-listeners
Nov 3, 2026
Merged

KATT merged 2 commits into
trpc:mainfrom
brennanbutler01:fix/dispose-http-abort-listeners

Conversation

@brennanbutler01

@brennanbutler01 brennanbutler01 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

Reusing an AbortSignal for completed httpLink or httpBatchLink requests leaves an additional abort listener on the caller's signal after each request. Five sequential requests leave five listeners, even when the injected fetch implementation registers none. The same happens when a request fails.

Add explicit cleanup to the internal signal race helper and call it from link teardown. Cleanup releases input listeners without aborting an already consumed response. When one input aborts, remove the listeners from the other inputs too. Existing callers of raceAbortSignals keep its AbortSignal return type.

This follows the unsubscribe-cancellation changes in #7469; it preserves their behavior and handles listener lifetime after completion. It does not change batch cancellation into cancellation on the first aborted operation.

Verification

  • 49 focused tests passed: 19 new signal/link tests and 30 existing tests in links.test.ts, splitLink.test.ts, createChain.test.ts, and dedupeLink.test.ts.
  • Against unchanged main (8b649ad874a8fe97c73962d4617912231b975736), 11 of the 16 new link cases fail; the five cancellation/response controls pass. All 16 pass with the fix.
  • Covers success, procedure errors, fetch errors, invalid response bodies, unsubscribe, pre-aborted signals, cancellation during body reading, partial batch cancellation, and preservation of caller-owned listeners.
  • Separate public-client reproductions with controlled fetch and a real loopback server leave zero caller listeners after repeated success/error responses. Active cancellation still rejects requests.
  • Focused TypeScript checks passed with 5.9.3 and 6.0.3. ESLint and Prettier checks passed for all five changed files.

Local validation used isolated tooling (Vitest 4.1.10, upstream source aliases and snapshot settings, jsdom for existing tests and Node for listener inspection). A 15-specifier lockfile sync aligns the workspace references with the v11.22.1 release on main; no new dependencies were added. GitHub CI passed build, typecheck, unit and integration tests, all end-to-end jobs, lint, declaration-file consumer tests, and CodeQL on the current head. Current workflow results. Four Vercel preview checks remain red: next-prisma-websockets-starter and next-sse-chat require tRPC team authorization, while examples-todomvc and next-prisma-starter deployments failed.

Prepared with assistance from OpenAI Codex; focused validation ran locally and the current full suite ran in GitHub Actions.

βœ… Checklist

  • I have followed the steps listed in the contributing guide. Focused local checks and upstream continuous integration passed.
  • No public API documentation change is needed.
  • I have added tests related to the changes made.

Summary by CodeRabbit

  • Bug Fixes
    • Improved cancellation handling for HTTP requests and batched requests. Unsubscribing now reliably cancels active work, including while a response body is being read.
    • Prevented request cleanup from removing abort listeners added by callers, and ensured cancellation signals are cleaned up after requests finish or fail.
    • Fixed behavior around already-aborted signals and request setup errors, reducing the risk of lingering listeners or unexpected cancellation.

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack β†’

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The client now exposes a cleanup-capable abort-signal race and uses it in HTTP and batch links. The links clean up combined-signal listeners during teardown and synchronous request-construction failures. Added tests cover signal cleanup, request outcomes, and batch cancellation.

Changes: Abort Signal Cleanup

Layer / File(s) Summary
Cleanup-aware signal racing
packages/client/src/internals/signals.ts, packages/client/src/internals/signals.test.ts
raceAbortSignalsWithCleanup returns a composed signal and a cleanup function. It removes listeners when an input aborts or cleanup runs. Tests cover aborted inputs, cleanup, and ignored nullish inputs.
HTTP link cleanup wiring
packages/client/src/links/httpLink.ts, packages/client/src/links/httpBatchLink.ts, packages/client/src/links/httpAbortCleanup.test.ts
Both HTTP links use the cleanup-capable signal race. They call cleanup during teardown, and httpLink also calls it if request creation throws synchronously. Tests cover request outcomes and cancellation behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: katt

Merge Risk: Minimal Β· up to 2b929

The change releases completed-request listeners while preserving active request and batch cancellation. No actionable merge-blocking issue remains.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: releasing abort listeners from completed HTTP requests.
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix Β· Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: trpc/trpc
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 3cf9541
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b18e6c83-75f4-415e-98e3-700f1140cf79
Commits

Reviewing files that changed from the base of the PR and between ed4d631 and 2b929aa.

Files selected for processing: 3
  • packages/client/src/links/httpAbortCleanup.test.ts
  • packages/client/src/links/httpBatchLink.ts
  • packages/client/src/links/httpLink.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@vercel

vercel Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
examples-todomvc Ready Ready Preview Nov 3, 2026 2:55pm UTC
next-prisma-starter Ready Ready Preview Nov 3, 2026 2:55pm UTC
og-image Ready Ready Preview Nov 3, 2026 2:55pm UTC
trpc-next-app-dir Ready Ready Preview Nov 3, 2026 2:55pm UTC
www Ready Ready Preview Nov 3, 2026 2:55pm UTC

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@trpc/client

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

@trpc/next

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

@trpc/openapi

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

@trpc/react-query

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

@trpc/server

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

@trpc/tanstack-react-query

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

@trpc/upgrade

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

commit: 2b929aa

@brennanbutler01
brennanbutler01 marked this pull request as ready for review September 18, 2026 11:09
@brennanbutler01
brennanbutler01 requested a review from a team as a code owner September 18, 2026 11:09
Copilot AI lite review requested due to automatic review settings September 18, 2026 11:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟑 Changes recommended

Synchronous request-construction failures can still leak abort listeners in httpLink.ts.

1 open finding

🧠 Review effort: Lite

Comment thread packages/client/src/links/httpLink.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟒 Approval recommended

No unresolved blocking issues remain, and the reviewed changes have comprehensive test coverage.

0 open findings

1 resolved since last review

🧠 Review effort: Lite

@brennanbutler01

Copy link
Copy Markdown
Contributor Author

I fixed the setup-throw path by calling cleanup() when universalRequester throws before returning a promise, and added FormData and octet-query regressions. The focused suite passes (18 tests); client typecheck, ESLint, and Prettier pass. The Bun E2E job still fails on jsonl.ts:308, which has the same blob as the PR base.

Copilot AI lite review requested due to automatic review settings October 11, 2026 04:42
@vercel

vercel Bot commented Oct 29, 2026

Copy link
Copy Markdown

@KATT is attempting to deploy a commit to the trpc Team on Vercel.

A member of the Team first needs to authorize it.

@KATT KATT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ€– Thanks @brennanbutler01! I rebased this, dropped an unrelated lockfile change, and gave the link tests readable names. LGTM: finished requests now remove their abort listeners from a reused signal, and cancellation works as before. The tests fail without the fix.

@KATT
KATT added this pull request to the merge queue Nov 3, 2026
Merged via the queue into trpc:main with commit 238821d Nov 3, 2026
50 of 53 checks passed
@github-actions

github-actions Bot commented Nov 4, 2026

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 Nov 4, 2026

This branch was successfully deployed

5 active (1 outdated) deployments
Preview – www β€” 2b929aa0 Deployed Nov 3, 2026 by vercel[bot]
Preview – examples-todomvc β€” 2b929aa0 Deployed Nov 3, 2026 by vercel[bot]
Preview – next-prisma-starter β€” 2b929aa0 Deployed Nov 3, 2026 by vercel[bot]
Preview – trpc-next-app-dir β€” 2b929aa0 Deployed Nov 3, 2026 by vercel[bot]
Preview – og-image β€” ed4d6315 Deployed Oct 31, 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.

4 participants