fix: convert node readable to web stream in honoWrapper#2315
fix: convert node readable to web stream in honoWrapper#2315alexander-akait merged 4 commits intomainfrom
Conversation
Wrap the Node fs.ReadStream in a Web ReadableStream we control before handing it to Hono. This routes the response through @hono/node-server's responseViaCache fast path (writeFromReadableStream) and bypasses Node's internal Readable.toWeb adapter, whose late error/close propagation caused intermittent "TypeError: Invalid state: ReadableStream already closed" on Windows + Node 20. All controller transitions are guarded so duplicate end/error events from the underlying fs stream cannot crash the Web stream controller.
Keep src/index.js focused on the wrapper logic and put the node-readable -> web-stream adapter alongside the other stream/response helpers in src/utils.js.
|
|
Track the upstream race so we can drop the helper once honojs/node-server#233 / #299 land and the minimum supported Node version no longer hits the Readable.toWeb adapter bug.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2315 +/- ##
==========================================
- Coverage 93.54% 92.70% -0.84%
==========================================
Files 3 3
Lines 960 1001 +41
Branches 302 311 +9
==========================================
+ Hits 898 928 +30
- Misses 57 65 +8
- Partials 5 8 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Wrap the Node fs.ReadStream in a Web ReadableStream we control before
handing it to Hono. This routes the response through @hono/node-server's
responseViaCache fast path (writeFromReadableStream) and bypasses Node's
internal Readable.toWeb adapter, whose late error/close propagation
caused intermittent "TypeError: Invalid state: ReadableStream already
closed" on Windows + Node 20.
All controller transitions are guarded so duplicate end/error events
from the underlying fs stream cannot crash the Web stream controller.