Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
1b153d2 to
c1650ff
Compare
…ent leaves RPC SSE and OpenAPI subscriptions now hand a finalizer that fails as the stream is interrupted, or a generator that throws from finally after the client disconnects, to onError instead of dropping it.
c1650ff to
1f0dea9
Compare
…ent leaves (#7908) RPC SSE and OpenAPI subscriptions now hand a finalizer that fails as the stream is interrupted, or a generator that throws from finally after the client disconnects, to onError instead of dropping it.
|
🤖 CI was green, so this landed squashed on |
…ort of #7888) A subscription's iterator runs on after the client stops it or its socket closes, and what it throws then (a generator's `finally` once its signal aborts, a `return()` that rejects) was dropped on both socket handlers. v11's adapter reports it to `onError` since #7888. #7908 gave the HTTP subscription handlers `reportSubscriptionTeardown`; the v11 interop socket and the native socket now pass it in a subscription call's services too, so the same failures reach `onError`, except an `AbortError`, which is how an aborted call ends. Co-authored-by: Alex / KATT <[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
onErrornever heard about it. Two cases do this:Streamsubscription whose finalizer fails as it is interrupted, for exampleStream.ensuring(Effect.die(...)).async function*that throws fromfinallyafter the client leaves.returnUnawaiteddoesn't wait for a generator'sreturn(), because a generator awaiting its signal would deadlock. It swallowed that rejection.onErroris the only place left to surface the failure. Alex's rule is that a failing finalizer must surface, never vanish. This found gap came up while porting fix(server): settle pending next() on abort and ignore teardown emissions in observableToAsyncIterable #7867/fix(server): don't crash when a subscription's teardown throws on abort #7884 to fix(trpc): an aborted subscription yields what it received, and a failing teardown reaches the loop instead of crashing #7906.v12as 93fb95a) and reuses its producer fiber.What
reportTeardown(stream, report)ininternal/effects.ts:Queuethat the reader reads back. When the reader's scope closes, anEffect.addFinalizerinterrupts the producer and reads itsExit. TheCausewithout its interrupts is the teardown failure.take) or was interrupted only. A failure the reader did get isn't reported again.endOnAbortnow shares the sameproducehelper. Its behaviour is unchanged.returnUnawaited(iterable, onLateFailure): what the iterator throws after the stream stopped waiting goes toonLateFailure. That covers both thenext()that was in flight andreturn()'s rejection. Without a callback, it behaves as before.SubscriptionTeardown, an internalContext.Referencethat defaults toundefined:toEventStreamreads it from the call's services. When it is set, it wrapsStreamsubscriptions inreportTeardownand passes the callback toreturnUnawaited.reportSubscriptionTeardown(report)builds the services. It skipsAbortError, because that is how a source aborted by the call'ssignalends, and runs the failure throughnormalizeCause.server/handler/subscription.ts) and the OpenAPI handler (for subscriptions) pass these services tocore.run. The report callsonErrorwithtype: 'subscription'and the path.returnUnawaitedis shared..agent-docs/notes/benchmarks.mdis updated.Alternatives considered
Stream.onExiton the subscription stream. It passes for RPC but fails for OpenAPI. Probes showed that when the reader is interrupted while handling a value, the stream's own exit is a plain interruption and the finalizer's defect is missing. OpenAPI's keep-aliveStream.mergehits exactly that timing. The fiber that runs the stream still gets the defect in itsExit, which is why the producer fiber is needed.Testing
expected [] to have a length of 1and pass after the change:server/handler/fetch-edges.test.ts: RPC SSE.openapi/openapi.test.ts: OpenAPI.Streamwhose finalizer dies and anasync function*that throws fromfinallyonce its signal aborts, and checks thatonErrorgets exactly one teardown error with its path andtype: 'subscription'.internal/effects.test.ts, four new unit tests:reportTeardownreports when its reader is interrupted mid-value, which is the caseStream.onExitmisses.returnUnawaitedhands afinallythrow toonLateFailure.pnpm fix,pnpm typecheck,pnpm test(1,971 passed) andpnpm coverageall pass. After rebasing onto the latestv12, typecheck and the 656 tests underinternal,server,openapiandclientpass again.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.