[PR #760] [MERGED] fix: clean up request context on stream error in deferUntilStreamConsumed #821

Closed
opened 2026-05-06 13:10:18 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/760
Author: @NathanDrake2406
Created: 4/3/2026
Status: Merged
Merged: 4/3/2026
Merged by: @james-elicx

Base: mainHead: fix/stream-error-context-leak


📝 Commits (1)

  • 6c85dd3 fix: clean up request context on stream error in deferUntilStreamConsumed

📊 Changes

2 files changed (+68 additions, -7 deletions)

View changed files

📝 packages/vinext/src/server/app-page-stream.ts (+13 -7)
📝 tests/app-page-stream.test.ts (+55 -0)

📄 Description

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)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/760 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 4/3/2026 **Status:** ✅ Merged **Merged:** 4/3/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/stream-error-context-leak` --- ### 📝 Commits (1) - [`6c85dd3`](https://github.com/cloudflare/vinext/commit/6c85dd37c1e9f18465ce638a755f606629dc659f) fix: clean up request context on stream error in deferUntilStreamConsumed ### 📊 Changes **2 files changed** (+68 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/server/app-page-stream.ts` (+13 -7) 📝 `tests/app-page-stream.test.ts` (+55 -0) </details> ### 📄 Description ## 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 - [x] Test: stream that errors mid-consumption → onFlush callback still invoked - [x] Test: immediate stream error → onFlush called exactly once (idempotent guard) - [x] Existing app-page-stream tests pass (11/11) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:10:18 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#821
No description provided.