Repository navigation
refactor(server): start the sse maxDurationMs timer alongside the stream it ends - #7699
Conversation
β¦eam it ends Co-authored-by: Cursor <[email protected]>
|
No actionable comments were generated in the recent review. π βΉοΈ Recent review info
π Walkthrough
Merge Risk: βͺ Minimal Β· up to
|
@trpc/client
@trpc/next
@trpc/openapi
@trpc/react-query
@trpc/server
@trpc/tanstack-react-query
@trpc/upgrade
commit: |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
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. |
Follow-up to #7666.
What changed
resolveResponseno longer starts the SSEmaxDurationMstimer inside each RPC call and threads aclearMaxDurationTimercallback back out throughRPCResultOk(along with acatchcleanup and a try/catch aroundinitResponse).Instead:
RPCResultOkcarries a singleabort?: ReturnType<typeof combinedAbortController>, set only for subscriptions.abort.controller.abort().onStreamEndclears the timer and removes the abort listener. It runs when the stream finishes, when a read errors, and when the body is cancelled.onAbortcallsonStreamEnd()and thenreader.cancel().Because the timer only exists once there is a stream to end, the paths where the procedure throws or
responseMetathrows never create one, so they need no cleanup.Behaviour note
Max duration is now measured from when the SSE stream is created, not from before the procedure (and its middlewares) runs. In practice that is usually a difference of a few milliseconds.
Why not
usingThe timer has to outlive
resolveResponse: it lives as long as the response body, so a scope-boundusingdisposal doesn't fit.Tests
sse maxDurationMs timer is not left pending when the subscription %s(inpackages/tests/server/adapters/fetch.test.ts) now has astartsTimercolumn. It istruefor "completes", "is cancelled" and "errors the stream", andfalsefor "throws" and "fails in responseMeta". The test asserts how many max-duration timers were created and that none of them were left uncleared.Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit