Conversation
…he server Cancelling a batched stream now aborts the batch request once only cancelled subrequests could still be running on the server. Before, the batch was aborted only when every subrequest sent a cancel, so a sibling that had already finished kept the connection open and the server generator running.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Cancellation gating rewritten in
BatchLinkPlugin— the oldactiveCountcounter (decremented per cancel, abort at zero) is replaced byopenRequestIds/cancelledRunningRequestIdssets, so the batch aborts as soon as only cancelled subrequests are still running rather than waiting for every subrequest to be cancelled. - Server-message completion tracking — a new
isLastServerMessagehelper classifies terminal peer messages (responsewith body/binary or no content-type +standard-serverhint,event-streamclose/error,octet-streamclose: true,cancel), anddecodeLengthPrefixedStreamnow takes areceivecallback that removes finished ids and re-checks the abort condition. - Tests — new
startStreamingBatchhelper with 5 unit tests covering abort-on-only-cancelled, keep-open-while-other-stream-runs, cancel-after-server-finished, cancelled-stream-finishes-first, and pre-batch cancel; plus an e2e test across node-http, hono-fetch and both compression setups asserting the cancelled endless generator stops and live streams arrive in full.
I verified the wire shapes against @standard-server/peer v0.10.0: every server terminal message kind is recognized, and stream/cancel (the one kind that returns false) is only emitted for client request-body streams, which the batch plugin never batches. I also confirmed peer.close uses Queue.close() (which preserves buffered items) rather than abort(), so aborting the batch to stop a cancelled stream cannot discard already-received buffered data for the other subrequests. The unit and e2e suites pass, and type:check and eslint are clean on all three files.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Merging this PR will improve performance by 12.74%
Performance Changes
Tip Curious why performance improved? Comment Comparing |
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/bun
@orpc/client
@orpc/cloudflare
@orpc/contract
@orpc/experimental-effect
@orpc/evlog
@orpc/hibernation
@orpc/json-schema
@orpc/experimental-lock
@orpc/experimental-msw
@orpc/nest
@orpc/next
@orpc/node
@orpc/openapi
@orpc/opentelemetry
@orpc/pinia-colada
@orpc/pino
@orpc/publisher
@orpc/ratelimit
@orpc/server
@orpc/shared
@orpc/swr
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/zod
commit: |

Cancelling a batched stream now stops it on the server. Before, the batch request was aborted only once every call in it had been cancelled, so if another call in the same batch had already finished, the connection stayed open and the cancelled procedure kept running. An endless generator never stopped.
Fixes
Testing
ReadableStream, an event iterator and a cancelled endless generator. The live streams arrive in full and the generator stops. It fails onmain.