Commit Graph
12918 Commits
Author SHA1 Message Date
Matteo Collina 472d501591 stream: keep async context of the pipeTo pump
The pipeTo() pump re-enters from the destination's ready hook, which
writableStreamUpdateBackpressure invokes synchronously, and from the
chunk steps of its read request. Both run in the async context of the
code that cleared the backpressure or enqueued the chunk, so the
source's pull() and the writes issued after a resumption observed that
context instead of the one of the pipeTo() call, as they did with the
promise-based pump. Capture the async context frame when the pipe starts
and run the pump in it.

Refs: https://github.com/nodejs/node/issues/66906
Refs: https://github.com/nodejs/node/pull/65138
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67054
Refs: https://github.com/nodejs/node/pull/67052
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2026-11-21 14:47:06 +01:00
Filip Skokan 94f626c8aa tls: configure TLS 1.3 ciphers with BoringSSL
Translate cipher-suite names into protocol IDs for BoringSSL's TLS 1.3
configuration API. Handle duplicates and unknown names, reject nonempty
lists without a supported suite, and implement honorCipherOrder through
preference flags.

Cover suite restrictions, explicit preference ordering, legacy-only
lists, runtime defaults, and command-line overrides.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66922
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-21 11:33:23 +01:00
Rafael Gonzaga a429fd0c97 child_process: propagate config-file permission flags to children
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/66830
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2026-11-19 16:44:47 +01:00
Marco Ippolito 7fb54df865 src: mark config file as stable
Signed-off-by: Marco Ippolito <marcoippolito54@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66830
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2026-11-19 16:44:47 +01:00
Marco Ippolito 0c6040b5a4 src: support multiple versions in node.config.json
Signed-off-by: Marco Ippolito <marcoippolito54@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66830
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2026-11-19 16:44:47 +01:00
Matteo Collina 3a7e1ad1e0 tls: reject hostnames with forbidden code points
domainToASCII() is implemented with the URL host parser, which stops at
path, query and fragment delimiters and percent-decodes. Passing a
hostname through it can therefore silently shorten the name, so
checkServerIdentity() validates a certificate against a host the
application never asked for: name resolution and SNI use the original
string, while the certificate is matched after normalization. Reject
hostnames containing a WHATWG forbidden host code point before matching.
None of these code points is valid in a DNS hostname, so failing closed
is safe.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67254
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2026-11-13 17:02:18 +01:00
Matteo Collina 1ea57dbce0 stream: trim webstreams sink wrappers and BYOB transfers
The close and abort methods of an underlying sink and the flush and
cancel methods of a transformer were each wrapped at construction in an
async closure that the controller kept for the stream's lifetime: two
per WritableStream and two per TransformStream, each with its context.
Store these one-shot methods as-is in the controller state next to the
object they belong to, and call them as that object's methods with the
spec's argument list through a promiseCall helper that keeps the
reference implementation's adoption ticks. The per-chunk methods (write,
transform) keep their closures, which make the method a constant for the
optimizing compiler on the hot paths; so does the source's cancel
wrapper, since the readable stream's construction path is sensitive to
any change in its inlining budget.

In the byte controller, the transfer of a pull-into descriptor's buffer
when it is committed is dropped: nothing can reach that buffer any more,
since it was transferred when the descriptor was created and the BYOB
request that exposed it is only ever invalidated together with a
transfer. The transfer of the first pending descriptor's buffer on
enqueue is likewise only needed while a BYOB request exposes it.
Allocating an ArrayBuffer costs about half a microsecond, so those two
transfers were a large part of a BYOB read.

Bytes allocated per stream with user methods: WritableStream 1040 ->
844, TransformStream 1816 -> 1720. The microtask ordering of every user
method call is unchanged.

Benchmark results (20 runs, vs. the previous commit):

    webstreams/readable-read.js type='byob' n=100000           ***   17.14 %  ±1.80%
    webstreams/readable-async-iterator.js type='normal' n=100000        3.79 %  ±4.49%
    webstreams/from.js kind='sync' n=1000000                     *   -2.18 %  ±2.02%
    webstreams/js_transfer.js n=10000 payload='TransformStream'   *   -1.85 %  ±1.58%

The other 42 rows are within their confidence intervals; the two rows at
the 5% level are the expected number of false positives for 46
comparisons.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66702
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2026-11-13 17:02:18 +01:00
Qingyu Wang 2b50db1364 stream: fix pipeTo assert when writer is released during microtask
pipeTo defers each slow-path write to a microtask so it does not run
synchronously during enqueue(). A race allows the pipe to shut down and
release its writer after the write is scheduled but before it runs. The
deferred write then hits an ERR_INTERNAL_ASSERTION because
writer[[stream]] is undefined.

Skip the deferred write when shutdown has already started.

Fixes: https://github.com/nodejs/node/issues/63732
Signed-off-by: Qingyu Wang <wangqingyu.c0l1n@bytedance.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/63733
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-13 17:02:18 +01:00
Matteo Collina 5d541dcd26 stream: reject writes during WritableStream close
WritableStreamDefaultControllerProcessClose clears the controller
algorithms while the stream is still 'writable', before the sink close
settles. A write in that window, such as writer.write() after
writer.close() while the sink's close() or a TransformStream's flush()
is pending, reached the cleared size algorithm and failed an internal
assertion instead of being rejected as closing. Accept that state in
writableStreamDefaultControllerGetChunkSize so the write is rejected
with a TypeError, as it is once the stream has closed.

Refs: https://github.com/nodejs/node/issues/57272
Refs: https://github.com/whatwg/streams/issues/1341
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67058
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2026-11-13 17:02:18 +01:00
Matteo Collina ffddf27ec1 stream: keep async context of fromWeb writes
Writable.fromWeb() and Duplex.fromWeb() dispatch writes to the
WritableStream directly and complete them through a shared write
tracker. A write issued before the WritableStream had started was
queued and processed from its start step, so the sink ran in the async
context of the code that created the WritableStream, and the tracker
invoked the Node.js write callback synchronously from whatever context
completed the sink write, so the writes and final() it released ran
there too. The promise-based adapter waited for writer.ready and
received the result through a reaction, both in the context of the
Node.js write.

Dispatch writes issued before the start from a writer.ready reaction,
failing them if the stream was closed or errored meanwhile, and deliver
the write callback in the context of the Node.js write, from a reaction
when it completes in another context.

Refs: https://github.com/nodejs/node/issues/66906
Refs: https://github.com/nodejs/node/pull/65548
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67055
Refs: https://github.com/nodejs/node/pull/67052
Refs: https://github.com/nodejs/node/pull/67054
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2026-11-13 17:02:18 +01:00
Matteo Collina d5fa3be434 stream: keep async context of pipeTo watchers
The ClosedPromiseHook records that pipeTo() and tee() install as the
[[closedPromise]] of their reader and writer enqueued the watcher from
whoever settled the record. The source-closed, source-errored and
dest-errored steps of pipeTo() therefore ran in the async context of
the code that closed or errored the stream, so the destination's
close() and abort() and the source's cancel() observed the wrong
AsyncLocalStorage store. Capture the async context frame when the
hook is installed and register the reaction in it, as the spec's
promise reaction would.

Add a test that records the context each underlying source, sink and
transformer callback observes across readable, writable, transform,
pipe and tee scenarios, so scheduling shortcuts that drop the context
are caught.

Refs: https://github.com/nodejs/node/issues/66906
Refs: https://github.com/nodejs/node/pull/66424
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67052
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2026-11-13 17:02:17 +01:00
Matteo Collina c3fd64dc66 test_runner: use AsyncLocalStorage instead of async_hooks
Track the test that owns the current async context with an
AsyncLocalStorage instead of a createHook() init/destroy map.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66795
Refs: https://github.com/nodejs/node/pull/61030
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2026-11-13 17:02:17 +01:00
Matteo Collina 19646e46aa process: return unregister fn from finalization
process.finalization.register() and registerBeforeExit() now return
a function that removes only that registration, leaving other
registrations for the same object in place. The function does not
hold a strong reference to the object.

Each registration now uses its WeakRef as the unregister token, which
also makes process.finalization.unregister() remove the entries from
the FinalizationRegistry; previously it passed the object as the
token, which was never registered, so the call had no effect.

Refs: https://github.com/nodejs/node/pull/66482

Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
Assisted-by: pi
PR-URL: https://github.com/nodejs/node/pull/66482
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2026-11-13 17:02:17 +01:00
Matteo Collina fbe987cadc net: fail closed when BlockList peer address is unavailable
When a net.Server is configured with a `blockList`, the peer address is
looked up with getpeername() and checked before the connection is
accepted. If the peer address cannot be obtained (for example, the
connection was reset before getpeername(), causing
uv_tcp_getpeername() to return ENOTCONN), the access-control check was
silently skipped and the connection proceeded, allowing a blocked peer
to reach the application's 'connection' handler (fail open).

Fail closed: when a BlockList is configured but the peer address cannot
be determined, close the connection instead of bypassing the check. A
connection whose peer address cannot be obtained cannot be proven to be
allowed, so it must be refused.

Ref: https://github.com/nodejs/node/issues/66422
Ref: https://github.com/libuv/libuv/pull/5337

Signed-off-by: Matteo Collina <hello@matteocollina.com>
Assisted-by: pi
PR-URL: https://github.com/nodejs/node/pull/66640
Refs: https://github.com/nodejs/node/issues/66422
Refs: https://github.com/libuv/libuv/pull/5337
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-11-13 17:02:17 +01:00
Matteo Collina 78707d1bbc stream: trim TransformStream construction costs
Constructing a TransformStream allocated five closures for the sink and
source algorithms of its two sides, and each side adopted the start
promise through a wrapper promise plus a thenable job, so a stream
without a start() left about three kilobytes pending in the microtask
queue until the started steps ran. Per-stream creation bursts spend
most of their time copying that graph through the scavenger.

The sink and source algorithms are now shared functions that reach the
transform stream through a field on their controller state (the
controller is passed to the close, abort and cancel algorithms for
that), and the post-start steps of both sides are delivered by one
reaction chain on a shared promise, taking the same microtask hops as
the spec's start promise adoption: three after construction for a
non-thenable start result, two after the adopting promise settles for a
thenable one. The readable and writable transfer state records are
materialized on first transfer instead of per stream.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66643
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Mattias Buelens <mattias@buelens.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2026-11-13 17:02:17 +01:00
James M Snell 8a93a7a23f stream: make stream/iter from() cancellation waits cheaper
To stay cancellable while a source is pending, from() waits for every
value of an async source through waitForNormalization(). For each value
it created a PromiseWithResolvers(), raced it against the value with
SafePromiseRace(), which wraps both in new promises, and ran an async
function with try/finally. This was the largest per-batch cost of
normalizing an async source.

Wait with a single promise and a single reaction on the value instead,
and reject that promise directly on cancellation. The outcome is
unchanged: the value's result, its rejection, or the cancellation
reason, whichever comes first, and the cancellation reason if the
normalization was cancelled by the time the value fulfills.

With an async generator yielding 16-byte chunks, pipeTo() is about
1.7x faster and iterating from() about 1.75x faster.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66648
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-11-13 17:02:17 +01:00
Matteo Collina d7c904799d diagnostics_channel: fix default callback context
traceCallback() defaults to a frozen context but writes the callback's
result or error to it. Allocate a fresh context when undefined is passed
and subscribers are present, matching traceSync() and tracePromise().
Set the prototype after allocation to avoid dictionary-mode properties.

Assisted-by: pi
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66481
Reviewed-By: Bryan English <bryan@bryanenglish.com>
2026-11-13 17:02:16 +01:00
James M Snell 1db3d713a1 stream: guard shareSync() against re-entrant source reads
If a shareSync() source read from a consumer of the same share while
producing a value, the nested read re-entered the source iterator.
For generators this threw "Generator is already running" from inside
the nested read, which recorded that error as the share's source
error while the outer read was still in progress, leaving every
consumer in an error state.

Fail the nested read with ERR_INVALID_STATE before touching the
share's state. The source sees the error and may handle it; if it lets
it escape, it becomes the source error as with any other source
failure.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66483
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-13 17:02:16 +01:00
James M Snell d31a8adafd stream: reject drop-newest backpressure in shareSync()
With 'drop-newest', a shareSync() consumer that needed to pull while
the buffer was at the budget discarded one entry from the source and
then returned { done: true } even though the source was not exhausted.
for...of loops, and anything else that trusts the iterator protocol,
silently stopped consuming. There is no correct alternative in a
synchronous context: the slowest consumer cannot advance while another
consumer's next() is running, so the call can neither wait for budget
nor keep discarding until budget is released.

Reject 'drop-newest' in shareSync() with ERR_INVALID_ARG_VALUE, as is
already done for 'unbounded'. The two tests that asserted the previous
"done but not detached" behavior are replaced by one that checks the
rejection. Also document how 'unbounded' and 'drop-newest' make the
async share() wait for the slowest consumer.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66483
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-13 17:02:16 +01:00
James M Snell abc4c59a8e stream: detach shareSync consumers on strict budget errors
When a shareSync() consumer needed to pull while the buffer was at or
above the budget under the 'strict' policy, it threw ERR_OUT_OF_RANGE
but stayed registered. Neither for...of nor a pullSync() transform
pipeline calls return() when next() throws, so the abandoned consumer
kept its cursor forever, pinned every entry pulled afterwards, and made
the remaining consumers fail with ERR_OUT_OF_RANGE as well.

Detach the consumer before throwing, as the async share() already does
(see 1ad67bc66b), and document the behavior for both.

The spec notes that a rejected strict pull does not terminate the
consumer's iterator so that it may be retried. That is not safe with
the common iteration patterns, and will be raised with the spec
editors.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66483
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-13 17:02:16 +01:00
Matteo Collina 87d619fa48 stream: share webstreams async iterator methods
ReadableStream.prototype.values() built each iterator from an object
literal with a computed symbol-key method plus five closures. Such a
literal is rebuilt through the runtime on every evaluation, costing
close to a microsecond per iterator, which dominates iterating a
short-lived stream.

Move next() and return() to a shared ReadableStreamAsyncIterator
prototype, as for any WebIDL async iterator, and keep the per-iterator
state in its read request. The prototype chain and property shape are
the ones WPT checks; the placeholder AsyncIterator object in util.js is
no longer needed. As in WebIDL, next() and return() now reject when
called on something that is not a ReadableStream async iterator, and
iterators no longer carry own next/return properties.

Add an async-iterator kind to benchmark/webstreams/lifecycle.js.

webstreams/lifecycle.js kind='async-iterator'   ***  +16.22%

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66392
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
2026-11-13 17:02:16 +01:00
James M Snell 842bd97846 stream: update ShareImpl to retain factory abort listener
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/66030
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-13 17:02:16 +01:00
James M Snell 39d1a5efd3 stream: make Broadcast.from() only return the Broadcast
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/66030
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-13 17:02:16 +01:00
James M Snell 4179233307 stream: have broadcast clean factory listeners on cancel
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/66030
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-13 17:02:16 +01:00
Matteo Collina aefc7f00e3 buffer: add Buffer.stringLength()
Add `Buffer.stringLength(input[, encoding])`, the counterpart of
`Buffer.byteLength()`: it returns the number of UTF-16 code units that
`buf.toString(encoding)` would produce, without decoding.

For UTF-8 the count is computed with simdutf. Invalid input is counted
with the same maximal-subpart replacement that the decoder applies, so
the result always matches `toString().length`. The other encodings are
computed from `byteLength` alone.

This lets code that accumulates streamed input check the result against
`buffer.constants.MAX_STRING_LENGTH` and size its memory budget before
decoding.

Refs: https://github.com/nodejs/node/issues/66062
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66064
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-11-13 17:02:15 +01:00
Matteo Collina d12cc45e24 stream: destroy half-open sockets after iteration
Async iteration left the writable side of `allowHalfOpen` duplexes open
after clean EOF. For `net.Socket` instances, this retained a live handle
after the peer disconnected.

Restore default iterator destruction. Callers that need to continue
writing can use `iterator({ destroyOnReturn: false })`.

Assisted-by: Codex
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/65986
Fixes: https://github.com/nodejs/node/issues/65110
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-13 17:02:15 +01:00
James M Snell dd23e9e514 stream: fixup stream/iter to drop at most one entry per share call
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/66028
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-11-13 17:02:15 +01:00
James M Snell 7e1ae1757b stream: reject unbounded at SyncShare construction
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/66028
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-11-13 17:02:15 +01:00
James M Snell 251c382359 stream: make Broadcast.from abort its background pump
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/66028
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-11-13 17:02:15 +01:00
Caleb Everett 5dc8afba5f stream: fix async iteration of undefined chunks
The hand-rolled async iterator introduced in
https://github.com/nodejs/node/pull/64447 unwraps thenable chunks
before delivering them, but guards the `then` access with
`chunk !== null` while the dereference itself requires `chunk != null`.
An object mode stream carrying an `undefined` chunk therefore threw

  TypeError: Cannot read properties of undefined (reading 'then')

Because the throw happens in a microtask rather than rejecting the
iterator's promise, it surfaces as an uncaught exception that
terminates the process instead of a catchable stream error.

`undefined` is a legal chunk value: doc/api/stream.md documents object
mode chunks as "any JavaScript value other than `null`" and reserves
`null` as the end-of-stream sentinel. `readable.push(undefined)`
returns true in object mode, so the stream accepts the value and then
crashes on the way out.

Read `then` with optional chaining at both sites so that `undefined` is
delivered as a value while `null` keeps signalling end-of-stream.
`then` is still read at most once, so a getter cannot observe a second
access.

Refs: https://github.com/nodejs/node/pull/64447
Assisted-by: a closed-source coding agent
Signed-off-by: Caleb ツ Everett <calebev@amazon.com>
PR-URL: https://github.com/nodejs/node/pull/65969
Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-13 17:02:15 +01:00
James M Snell a0bcf847af stream: make consumer signals on longer alter source precedence
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65658
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-13 17:02:15 +01:00
James M Snell 292874a419 stream: ensure pre-existing writes drain before EOF and end() waits
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65658
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-13 17:02:15 +01:00
James M Snell 30704d09c4 stream: canWrite and ondrain now reflect physical capacity
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65658
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-13 17:02:15 +01:00
James M Snell c475ec30d0 stream: ensure pipeToSync requires synchronous close
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65652
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-13 17:02:14 +01:00
James M Snell 3da0f1e417 stream: defend against re-entrancy in writev
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65652
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-13 17:02:14 +01:00
James M Snell c3f4cc094c stream: ensure stability of stored metadata
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65652
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-13 17:02:14 +01:00
Matteo Collina 729003c976 stream: speed up async iteration of Readable
Replace the async generator backing Symbol.asyncIterator with a
hand-rolled iterator. The generator machinery costs several extra
promise allocations and microtask hops per chunk: yield awaits the
yielded value and resolves the pending request through separate
promises. Buffered chunks are now delivered as an already-resolved
promise, one microtask sooner than before.

Thenable chunks are still awaited before delivery, requests received
while a next() is outstanding are queued, and return()/throw() before
the first next() complete the iterator without touching the stream.

The earlier delivery is observable by code racing an abort against
the first chunk. The flatMap AbortSignal test relied on such a race;
it is reworked to abort deterministically while two mappers are in
flight, asserting the concurrency limit, in-flight cancellation and
rejection, without depending on delivery timing or timers.

streams/readable-async-iterator.js sync='yes': +32.59% (***)
streams/readable-async-iterator.js sync='no': +9.84% (***)

Assisted-by: Claude Fable 5
Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/64447
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Mattias Buelens <mattias@buelens.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
2026-11-13 17:02:11 +01:00
Mert Can Altin 4613bec088 crypto: improve random synchronous number generation performance
Instead of creating a RandomBytesJob object, it calls CSPRNG()
directly now.

Assisted-by: Claude Code
Signed-off-by: Mert Can Altin <mertgold60@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66348
Backport-PR-URL: https://github.com/nodejs/node/pull/66970
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2026-11-11 17:28:11 +01:00
Filip Skokan fe956fecdc crypto: use backend cSHAKE and KMAC
Require cSHAKE and KMAC output lengths and KMAC key lengths to be
multiples of 8 bits. KMAC keys must be at least 32 bits. Share these
restrictions between operations and supports.

Use OpenSSL's KMAC provider for all supported inputs and its cSHAKE
implementation for non-empty function names or customization strings.
Keep using SHAKE when both cSHAKE parameters are empty. Remove the
custom Keccak framing, partial-bit handling, and short-key fallback.

Document the OpenSSL 4.0 requirement for non-empty cSHAKE parameters and
reject customization strings containing null bytes. Keep the documented
512-byte customization limit and let backend failures reach callers.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66237
Backport-PR-URL: https://github.com/nodejs/node/pull/66970
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2026-11-11 17:28:11 +01:00
Filip Skokan 06254beb5d crypto: separate conversion from validation
Convert algorithm dictionaries on the original receiver, with name
read once. Validate normalized parameters in their operation steps
after the method-level key checks and generation usage checks.

This also makes Argon2 validation use converted parallelism and keeps
later dictionary conversion errors ahead of semantic parameter errors.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66237
Backport-PR-URL: https://github.com/nodejs/node/pull/66970
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2026-11-11 17:28:11 +01:00
Filip Skokan f393f8be84 crypto: use internal random buffer bounds
Read buffer lengths and element sizes from internal slots in
randomFillSync() and randomFill(). Shadowed properties can otherwise
skip filling, change the selected range, or fail a native bounds check.

Use the intrinsic byte length for the getRandomValues() quota check and
keep its delegation to randomFillSync().

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66237
Backport-PR-URL: https://github.com/nodejs/node/pull/66970
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2026-11-11 17:28:10 +01:00
Filip Skokan 1a2b5cc6ff crypto: use current FIPS state for availability
Refresh conditional algorithm registration on FIPS changes and use the
current state for parameter restrictions.

Use per-algorithm availability checks in normalization and native named
key generation. Remove getPqcKeyTypes().

Enable supports() tests under FIPS and cover state transitions in warmed
workers.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66160
Backport-PR-URL: https://github.com/nodejs/node/pull/66970
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2026-11-11 17:28:10 +01:00
Matteo Collina a8bd0e14c1 stream: skip idle webstreams start and watchers
A source without pull() has nothing observable left to do in its
post-start step, since the started flag only gates calls into the pull
algorithm. Set the flag right away instead of from a microtask, so a
push-style ReadableStream allocates neither the closure nor the task
and is not kept alive until the next microtask checkpoint.

pipeTo and tee hold the only references to their reader and writer, so
their [[closedPromise]] records are never observed as promises. Install
the watchers as the records themselves, as pipeTo's ready hook already
does, instead of materializing a promise plus reaction per side, and
hand the erroring/release probes one shared pending promise. The tee's
cancel promise is likewise materialized by the first branch cancel.

Microtask ordering is unchanged: each hook enqueues its watcher at the
position the promise reaction would have had.

node benchmark/compare.js --runs 20 over benchmark/webstreams (46 rows,
all others within the confidence interval):

webstreams/creation.js kind='ReadableStream'               ***  +172.40%
webstreams/creation.js kind='ReadableStream.tee'           ***   +20.47%
webstreams/creation.js kind='ReadableStreamBYOBReader'     ***   +15.66%
webstreams/creation.js kind='ReadableStreamDefaultReader'  ***   +14.53%
webstreams/lifecycle.js kind='pipe-to' (40 runs)           **    +10.98%

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66424
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-11 17:28:09 +01:00
Ved Chaudhari 3f0813199c querystring: fix value decoding after encoded keys
In the non-default parse() path, a key with more than one percent
escape could corrupt non-ASCII characters in its value.

Keep key characters out of the value's encoding check.

Assisted-by: claude:opus-5.5
Signed-off-by: vedchaudhari <vedc2853@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66553
Refs: https://github.com/nodejs/node/pull/66175
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2026-11-11 17:28:09 +01:00
Roberto Bianchi a64265166c http: reduce raw header name allocations
Reuse the values array instead of allocating a second result array.

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
PR-URL: https://github.com/nodejs/node/pull/66488
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-11-11 17:28:08 +01:00
Darius 992edabf00 lib: fix AbortSignal.any() nested composite leak
AbortSignal.any() copies the source WeakRefs of a composite input into
the new composite, so nested composites share them. Those WeakRefs were
also used as the unregister tokens for the registrations that prune a
composite's sources once they are collected. When an inner composite
was collected first, its cleanup therefore also unregistered the outer
composite from the same sources. An observed outer composite then
stayed in gcPersistentSignals, together with its listeners, even after
all of its sources were gone and nothing could abort it anymore.

Use each composite's own WeakRef as the unregister token instead, so
collecting one composite only removes its own registrations.

Fixes: https://github.com/nodejs/node/issues/66612
Refs: https://github.com/nodejs/node/pull/62367
Assisted-by: Claude Code
Signed-off-by: journaltraces <kxenk@protonmail.com>
PR-URL: https://github.com/nodejs/node/pull/66617
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-11-11 17:28:08 +01:00
Lazizbek Ergashev 1946de6356 module: fix require of imports with package map
Signed-off-by: lazerg <lazerg2@gmail.com>
Assisted-by: Claude Code
PR-URL: https://github.com/nodejs/node/pull/66565
Fixes: https://github.com/nodejs/node/issues/66562
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
2026-11-11 17:28:07 +01:00
James M Snell 2184500040 stream: fix fromSync() async input error messages
The ERR_INVALID_ARG_TYPE messages for async iterable and promise inputs
read "must be an a synchronous input (not AsyncIterable)", because the
error formatter adds "an" to expected-type strings that contain
uppercase letters. Rephrase them in lowercase.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66483
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-11 17:28:07 +01:00
James M Snell aebb924cc4 stream: bound pre-batched async values in from()
When an async source yielded an already-batched Uint8Array[] value,
from() passed it through as-is, however large it was. Every other
input shape (a sync source, or an array passed to from() or
fromSync() directly) splits such batches into batches of at most 128
chunks, which bounds the memory transforms must allocate per batch.

Apply the same bound to async sources. Batches within the bound are
still passed through without copying.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66483
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-11 17:28:07 +01:00
James M Snell d8f505f0ec stream: keep share buffer when all consumers detach
When the last consumer of a share() or shareSync() detached, the min
cursor fell back to the end of the buffer, so every buffered entry was
trimmed, including entries that the detaching consumer had not read.
The source had already produced that data, so consumers that attached
later silently skipped it.

Keep the buffer while there are no consumers, as broadcast() already
does, so late-joining consumers start at the oldest entry still in the
buffer. Document that the source stays open until the share is
cancelled or disposed.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66483
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-11 17:28:06 +01:00