Skip to content

fix: clean up request context on stream error in deferUntilStreamConsumed#760

Open
NathanDrake2406 wants to merge 1 commit intocloudflare:mainfrom
NathanDrake2406:fix/stream-error-context-leak
Open

fix: clean up request context on stream error in deferUntilStreamConsumed#760
NathanDrake2406 wants to merge 1 commit intocloudflare:mainfrom
NathanDrake2406:fix/stream-error-context-leak

Conversation

@NathanDrake2406
Copy link
Copy Markdown
Contributor

Summary

  • deferUntilStreamConsumed's pull() handler had no error path for upstream stream errors
  • When a component throws during streaming, clearRequestContext() was never called, leaking per-request state (headers, cookies, navigation context)
  • Normal completion (flush) and client disconnect (cancel) were handled correctly — only the error path was missing
  • Adds error handler that calls cleanup before propagating the error to the consumer

Test plan

  • Test: stream that errors mid-consumption → onFlush callback still invoked
  • Test: immediate stream error → onFlush called exactly once (idempotent guard)
  • Existing app-page-stream tests pass (11/11)

…umed

deferUntilStreamConsumed's pull() handler had no error path — when the
upstream RSC/SSR stream errored mid-consumption, the onFlush callback
(clearRequestContext) was never invoked, leaking per-request state.
The cancel hook handled client disconnect and the flush hook handled
normal completion, but stream errors were uncovered. Adds an error
handler that calls once() before propagating the error.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 3, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@760

commit: 6c85dd3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant