[GH-ISSUE #1002] fix: pumpReader silently swallows stream errors — getRawBuffer() returns incomplete ISR cache data #218

Closed
opened 2026-05-06 12:38:16 +02:00 by BreizhHardware · 0 comments

Originally created by @Divkix on GitHub (May 1, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/1002

James flagged this on #984 (review comment):

i was just looking at pumpReader above - it looks like it's swallowing errors that happen, so getRawBuffer could potentially return an incomplete buffer due to an error in pumpReader. i think we should probably be re-throwing errors caught there inside these functions.

Location: packages/vinext/src/server/app-ssr-stream.ts:51-54

    } catch (error) {
      if (process.env.NODE_ENV !== "production") {
        console.warn("[vinext] RSC embed stream read error:", error);
      }
    }

What happens: pumpReader() catches stream read errors but never re-throws. pumpPromise always resolves. Both finalize() and getRawBuffer() await pumpPromise and proceed as if all data is present. If the stream errored mid-read, getRawBuffer() returns a truncated ArrayBuffer with chunks read before the failure — and the ISR cache (src/server/app-page-cache.ts:357) writes this corrupt data silently.

Fix: Re-throw the error after the dev warning so pumpPromise rejects — finalize() and getRawBuffer() will then properly fail, and the existing catch in scheduleAppPageRscCacheWrite (line 376) already handles the error path for ISR.

    } catch (error) {
      if (process.env.NODE_ENV !== "production") {
        console.warn("[vinext] RSC embed stream read error:", error);
      }
+     throw error;
    }
Originally created by @Divkix on GitHub (May 1, 2026). Original GitHub issue: https://github.com/cloudflare/vinext/issues/1002 James flagged this on [#984 (review comment)](https://github.com/cloudflare/vinext/pull/984#discussion_r3172508848): > i was just looking at `pumpReader` above - it looks like it's swallowing errors that happen, so `getRawBuffer` could potentially return an incomplete buffer due to an error in `pumpReader`. i think we should probably be re-throwing errors caught there inside these functions. **Location:** `packages/vinext/src/server/app-ssr-stream.ts:51-54` ```ts } catch (error) { if (process.env.NODE_ENV !== "production") { console.warn("[vinext] RSC embed stream read error:", error); } } ``` **What happens:** `pumpReader()` catches stream read errors but never re-throws. `pumpPromise` always resolves. Both `finalize()` and `getRawBuffer()` await `pumpPromise` and proceed as if all data is present. If the stream errored mid-read, `getRawBuffer()` returns a truncated `ArrayBuffer` with chunks read before the failure — and the ISR cache (`src/server/app-page-cache.ts:357`) writes this corrupt data silently. **Fix:** Re-throw the error after the dev warning so `pumpPromise` rejects — `finalize()` and `getRawBuffer()` will then properly fail, and the existing catch in `scheduleAppPageRscCacheWrite` (line 376) already handles the error path for ISR. ```diff } catch (error) { if (process.env.NODE_ENV !== "production") { console.warn("[vinext] RSC embed stream read error:", error); } + throw error; } ```
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#218
No description provided.