Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
kState,
kType,
lazyTransfer,
markPromiseAsHandled,
nonOpCancel,
nonOpPull,
nonOpStart,
Expand Down Expand Up @@ -1569,9 +1570,18 @@
}

// Write the chunk - we're already in a separate microtask from enqueue
// because we awaited writer[kState].ready.promise above
// because we awaited writer[kState].ready.promise above.
//
// setPromiseHandled's job here is purely to silence the per-chunk
// unhandled-rejection event — the chain Promise + noop closure it

Check failure on line 1576 in lib/internal/webstreams/readablestream.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Non-ASCII character '—' detected. Consider replacing with: -
// would allocate are unobserved by anything else (errors propagate
// through writer.closed, which pipeTo monitors via watchErrored).
// markPromiseAsHandled sets V8's MarkAsHandled + MarkAsSilent flags
// directly, with no per-chunk allocation. The LAST state.currentWrite
// is awaited in waitForCurrentWrite during shutdown — markAsHandled
// does not affect that subsequent .then chain.
state.currentWrite = writableStreamDefaultWriterWrite(writer, chunk);
setPromiseHandled(state.currentWrite);
markPromiseAsHandled(state.currentWrite);

// Check backpressure after each write
if (dest[kState].backpressure) {
Expand Down Expand Up @@ -1675,7 +1685,10 @@
// "ReadableStreamPipeTo" step 15's "chunk steps".
queueMicrotask(() => {
this.state.currentWrite = writableStreamDefaultWriterWrite(this.writer, chunk);
setPromiseHandled(this.state.currentWrite);
// See comment in pipeTo's fast path on the markPromiseAsHandled vs
// setPromiseHandled choice. The per-chunk silencing has no other
// observer; errors reach pipeTo via writer.closed monitoring.
markPromiseAsHandled(this.state.currentWrite);
this.promise.resolve(false);
});
}
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/webstreams/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const {
kPending,
},
getPromiseDetails,
markPromiseAsHandled,
} = internalBinding('util');

const assert = require('internal/assert');
Expand Down Expand Up @@ -225,6 +226,7 @@ module.exports = {
kState,
kType,
lazyTransfer,
markPromiseAsHandled,
nonOpCancel,
nonOpFlush,
nonOpPull,
Expand Down
Loading