Repository navigation
Description
Provide environment information
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 20.19.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@tanstack/react-query: ^5.80.3 => 5.90.5
@trpc/client: canary => 11.7.1-canary.1+3ae1c3651
@trpc/next: canary => 11.7.1-canary.1+3ae1c3651
@trpc/react-query: canary => 11.7.1-canary.1+3ae1c3651
@trpc/server: canary => 11.7.1-canary.1+3ae1c3651
next: ^15.3.1 => 15.5.6
react: ^19.1.0 => 19.2.0
typescript: ^5.9.2 => 5.9.3
Describe the bug
When testing subscriptions on Vercel, I was surprised to experience timeouts of my lambdas, even though I've set sse.maxDurationMs to a duration shorter than my lambda's max duration.
After running more tests, I figured the subscription was correctly terminated but only when it yields a value:
https://stackblitz.com/edit/github-rmw4rvvn-lqfxkrsa?file=src%2Fpages%2Fapi%2Ftrpc%2F%5Btrpc%5D.ts
If I do not yield anything from the subscription handler, then it's never terminated and the signal is never aborted:
https://stackblitz.com/edit/github-rmw4rvvn-ertp6cer?file=src%2Fpages%2Fapi%2Ftrpc%2F%5Btrpc%5D.ts
Btw, I also noticed that when the subscription is terminated by maxDurationMs, it takes some time for the client to notice and reconnect. It would be great if there was a built-in way to proactively reconnect from the client in order to minimise the latency during reconnection. Maybe that could be a default behaviour when maxDurationMs is set? Please let me know if I'm missing something here.
Link to reproduction
To reproduce
Just look at the console log. Notice that we never log "🚫 subscription ended" but continue loggign 🔄 loop ${count} even though the 2s maxDurationMs is passed.
Additional information
No response
👨👧👦 Contributing
- 🙋♂️ Yes, I'd be down to file a PR fixing this bug!
Activity
Nick-Lucas commentedon Oct 29, 2025
Hey, thanks for sharing the stackblitz, that's always very helpful!
So my first instinct is you'll need to check the abort signal in appropriate places, similar to this:Without checking the abort signal yourself there's no way for the JS that's written to escape without yielding control to the consumer of the generator.That said my code there isn't working because the abort signal doesn't seem to be turning true when I refresh the preview area. I've seen this before where the web framework isn't appropriately propagating the signal and that can either be a bug in dev mode (seen that on cloudflare) or a configuration issue, but I'm not a nextjs expert so it's hard to say what to look at
Nick-Lucas commentedon Oct 29, 2025
Ah sorry, belay the first bit I can see it's being checked in the while condition, fuzzy morning brain!
The issue seems to be that abort isn't even being propagated though, so the latter note is something we'd need to check :)
testerez commentedon Oct 29, 2025
Thanks for having a look @Nick-Lucas !
If you look at my working example, you can see that the abort signal is sent after the iterator returned. That's probably the issue...
Nick-Lucas commentedon Oct 29, 2025
I think that might be a product of how we convert the nodejs IncomingMessage type (which nextjs uses) to a Request and AbortController - it fires the abort on connection close as well as on abort
trpc/packages/server/src/adapters/node-http/incomingMessageToRequest.ts
Lines 116 to 137 in d6bb04d
I would need to investigate more, but it's possible @juliusmarminge already knows something about this behaviour
nk1tz commentedon Dec 3, 2025
+1
fix(server): pass maxDurationMs timeout signal to subscription handle…
github-actions commentedon Dec 20, 2025
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.