Repository navigation
fix(client): stop a finished query from holding a streamed batch open - #8194
Conversation
`httpBatchStreamLink` aborts a batch's request once every operation's signal has aborted. trpc#8056 made a failed operation abort its own signal, but a successful one never did: `isDone` only kept the teardown from aborting it. So with a settled query in the batch, cancelling a streamed query left the request open, and the server kept running its generator. A query cancelled before its stream arrived kept it open until the server closed. A successful operation now aborts its own signal when its result has nothing left to stream, by the same test the server makes before it refuses a stream in a non-streaming request. A result that still holds a stream keeps its signal. The failed and rejected paths are unchanged.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@pengzh1 is attempting to deploy a commit to the trpc Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
trpc-bot
left a comment
There was a problem hiding this comment.
This fixes the leak, and the tests fail without it. A call that returns { a: Promise } still holds the batch open until its promise settles; we'll handle that in a follow-up.
…ettle (trpc#8195) ## Why - `httpBatchStreamLink` cancels a batch only after every call's signal aborts. - After trpc#8194, a call whose result holds deferred values (`{ a: Promise }`, a nested async iterable) never released its signal, even once they settled. So cancelling a streamed sibling left the request open and the server running. - Follows up trpc#8194 by @pengzh1. ## What - The JSONL consumer notes which head key (call) each chunk belongs to. It takes a new optional `onSettled({ key })`, called once every chunk under a key has closed. - The link aborts that call's signal then. - This also covers plain results, so it replaces trpc#8194's `isDataStream` check. - A part that's still pending keeps its call's signal, so it isn't cut off. ## Links None ## Alternatives considered - Walk the result in the link and await its promises: misses nested values and async iterables, and duplicates what the consumer already tracks. ## Testing Regression check: `cancels a batch holding a settled query with deferred values and a streamed query` and `keeps a batch open for a pending deferred value after a streamed query is cancelled` in `packages/client/src/links/httpAbortCleanup.test.ts`. Without the fix, the server never sees the cancellation. ## AI model Claude Opus 5.5 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- codesmith:footer --> --- <a href="https://dashboardbackend.blacksmith.sh/track/run-proof?expires=1798113206&installation_model_id=443568&pr_number=8195&ref=codesmith_pr_footer&repository=trpc%2Ftrpc&return_to=https%3A%2F%2Fgithub.com%2Ftrpc%2Ftrpc%2Fpull%2F8195&variant=proof_this_pr&signature=5006697306b944d3ecd54ec37862c82457d98afdcba901b4f1e60b0f45cdedf6"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-proof-this-pr-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-proof-this-pr-v2-light.svg"><img alt="Proof this PR" src="https://pr-comments-assets.blacksmith.sh/codesmith/proof-proof-this-pr-v2-dark-3x.png" width="121" height="28"></picture></a> <sup><a href="https://app.blacksmith.sh/trpc/codesmith/trpc/pr/8195?autoLogin=true&ref=codesmith_pr_footer">Open in [code]smith</a> · Need help on this PR? Tag <code>@codesmith-bot</code> with what you need.</sup> <!-- codesmith:autofix:disabled --> <!-- /codesmith:footer --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved handling of cancelled streams that share a batch with deferred results. Completed results now settle independently, while batches remain open for pending results until they finish. This helps streamed queries and deferred responses complete more reliably when a stream is cancelled, without prematurely ending work that is still pending. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…ts result is there Since #8194/#8195, an operation of a streamed batch lets go of it once its own chunks close. A call's signal ended when the call settled, or when its load stopped listening, which for a call for every item is before its runs have streamed. So the request was cut off under them. Now `httpBatchStreamLink`'s `settle()` ends a call's signal, as it does an operation's, and a call that settled no longer ends it on teardown. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in main up to #8195 (v11.31.2), with main's other commits since the last sync: automatic releases, the App Router examples, the /kitchen-sink showcase and the server and client fixes. - Workflows: main.yml, lint.yml, release.yml and subtree.yml are main's, reapplied to the v11-* copies with v12's paths, working-directory and setup action. v11-ci and v11-lint keep their push trigger on v12, which has no PRs. The setup action takes main's `example` input, installing ./v11, ./v11/packages/* and the example. - tooling/release: main's new git calls get --relative and <rev>:./ as before; pnpm-workspace.yaml is read as the repo root's. - Catalogs merge in place. oxlint stays at v12's 1.90.0: main's 1.92 can't load v12/vite.config.ts through Vite+ 1.1.0. v11's fastify importers resolve 5.12.8, as on main, so the v11 Fastify docs sample type-checks against one copy now that v11 emits with TypeScript 7.1. - www: both kitchen sinks stay. unindexedPaths is /v12 and /kitchen-sink; prerenderFilter keeps v12's /v12/docs exclusion; the root keeps v12's banner and home-version script beside main's announcement bar. package-links.test.ts gets a 30 s timeout: main's new v11 sources take it past 5 s beside the site's other tests. - Root package.json, AGENTS.md, .gitignore and the PR template stay v12's; main's changes go to v11/'s. Lint rules go to both .oxlintrc.json files. - v11/ paths that differ from main on purpose: the packages' prepack path, the sponsor image URLs, sse.ts's hand-driven iterator, handles.ts's inferFeatureFlags, and tooling/release's git paths. v12/ ports, in later commits: - #8195, #8194: a batched call's deferred values outlive a sibling's abort, and aborting a streamed call in a batch stops it. - #8027: localLink's createContext gets the call's abort signal. - #7935, #7936: an SSE error event or errorFormatter that throws ends the stream and is reported, in the v11 handler and native SSE. - #8146: the v11 handler's SSE writes `data:` for undefined. - #8126: FormData conversion errors in actions go through onError, and the bracket parser replaces a string leaf under an array index. - #8139: an empty pre-parsed JSON body is no input. - #8152, #8141: OpenAPI tuples with rest or optional elements. Left for a human: #8150 (retry a failed lazy load) reverses lazy-routers-on-effect.md; #7927 (an unreadable wsLink frame) would replace v12's skip-and-continue. Not needed: the rest, including the four security advisories, which v12's bracket parser, input handling and upgrade path already cover. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Aborting a streamed call after its head was ignored in a batch: its
values kept streaming and the server kept running its generator, since
the batch's request only closed when every caller stopped waiting before
an answer.
A batch head now says `deferred: true` when chunks follow, and the server
ends each such call with `{ i }`, as sockets' `chunkEnd`. A call holds
the batch until it has nothing left to stream or its caller aborts, which
fails its open values with CLIENT_CLOSED_REQUEST. Once a caller has left
and every call is released, the request aborts, so a sibling's deferred
values still stream to the end first.
Port of #8194 and #8195.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
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. |
Why
httpBatchStreamLinkbatch, then the streamed query is cancelled (the user navigates away,cancelQueries). The query cancels, but the request stays open and the server keeps running its generator.What
Links
Alternatives considered
isDataStream: that editsresolveResponse.ts, which feat(client,server): experimental nested queries in one request #8129 rewrites.Testing
cancels a batch holding a settled query and a streamed queryinpackages/client/src/links/httpAbortCleanup.test.tsfails onmain: the stream runs to tick 10 after the cancel.stops a streamed query cancelled before it streams, in a batch with a settled queryfails onmaintoo: the server'ssignalnever aborts.AI model
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit