stream: preserve mutable chunks in Web Stream adapters - #64579
seungwoo505 wants to merge 5 commits into
Conversation
|
Review requested:
|
| @@ -1260,4 +1262,5 @@ module.exports = { | |||
| validateHeaderName, | |||
| validateHeaderValue, | |||
| OutgoingMessage, | |||
| outgoingMessagePrototypeWrite, | |||
There was a problem hiding this comment.
The Web Streams adapter uses this export to compare the active write() method with the original OutgoingMessage.prototype.write.
This distinction preserves the native validation behavior without applying it to overridden write() implementations.
The reference is captured here so a later prototype monkey-patch is not mistaken for the original method.
97f5318 to
c08321a
Compare
|
Hi @bjohansebas, just a friendly follow-up on this. |
|
Sorry for the radio silence. Can you rebase again? |
|
Sorry, I just saw your message. |
Wait for native write callbacks when they can safely represent chunk consumption. For Duplex streams, corked writes, and custom or legacy write methods, pass private BufferSource copies to preserve completion timing. Coordinate callback completion with backpressure, aborts, and stream errors so a settled Web Streams write no longer exposes mutable bytes still retained by the native stream. Preserve native HTTP validation and SharedArrayBuffer backing when fallback copies are required. Signed-off-by: seungwoo <zoozoo1302@gmail.com>
Cover native callback completion, fallback copies, aborts, and error propagation for mutable BufferSource chunks passed to Node.js Web Streams adapters. Verify HTTP validation, SharedArrayBuffer backing, and Duplex and compression paths. Signed-off-by: seungwoo <zoozoo1302@gmail.com>
Rely on native stream validation after copying array buffer views. Keep object-mode writes on their existing completion timing, and remove adapter-only HTTP detection and prototype capture. Signed-off-by: seungwoo <zoozoo1302@gmail.com>
Remove overlapping override coverage. Verify object-mode writes settle independently of native callbacks. Exercise the Writable.toWeb(Duplex) path and keep native HTTP validation coverage. Assisted-by: Codex Signed-off-by: seungwoo <zoozoo1302@gmail.com>
c08321a to
062b9a0
Compare
|
Hi @mcollina, I’ve rebased the PR onto the latest main and resolved the conflicts. |
Use the Float16Array constructor captured during Node.js initialization instead of reading it from globalThis when the adapter is loaded. This prevents changes to the global constructor from affecting chunk cloning. Signed-off-by: seungwoo <zoozoo1302@gmail.com>
|
Benchmark GHA (webstreams / adapters): https://github.com/nodejs/node/actions/runs/36556500893 Results
Benchmark results:
|
|
The benchmark shows a significant drop for |
|
I’ve confirmed the performance regression shown in the benchmark. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #64579 +/- ##
==========================================
- Coverage 90.36% 90.36% -0.01%
==========================================
Files 792 792
Lines 275398 275793 +395
Branches 52776 52852 +76
==========================================
+ Hits 248877 249210 +333
- Misses 16937 17005 +68
+ Partials 9584 9578 -6
🚀 New features to boost your workflow:
|
When a Node.js writable is converted with
Writable.toWeb(), the Web Streamswrite()promise can currently settle as soon as the nativewrite()callreturns
true. That return value only represents backpressure, so the nativestream may still retain the supplied mutable BufferSource. Reusing the buffer
after awaiting the Web write can therefore change bytes that have not yet been
consumed.
This change:
unmodified
Writable;drain, aborts, and native streamerrors;
and legacy write paths where waiting for a callback would change existing
completion behavior;
The original native
Writable.prototype.writeandOutgoingMessage.prototype.writemethods are captured so patched methods andaccessors are classified and invoked consistently.
Validation included:
make -j4 test(full test suite passed)git diff --checkFixes: #64549