18553 Commits
Author SHA1 Message Date
Adithya kumar Reddy Gopavaram 2fb9bf8f83 zlib: handle close before initialization
Fixes #67485

Signed-off-by: Adithya kumar Reddy Gopavaram <91198686+ADITHYAKUMARREDDY@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/67507
Fixes: https://github.com/nodejs/node/issues/67485
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2026-11-25 18:20:41 +01:00
Tim Perry e4ed518b4f tls: fix OpenSSL compression leak that breaks tests under ASAN
This is not impactful in any way - it's a fixed leak of the openssl
record compression descriptors, about 24 bytes leaked total, once
per process. Not meaningful.

It is annoying if you want to run with ASAN & leak detection though,
since it's an unambiguous leak we trigger every time crypto is used.

Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66600
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2026-11-25 18:20:40 +01:00
Livia Medeiros b18660ed34 lib: recognize <LS> and <PS> as line terminators
Signed-off-by: LiviaMedeiros <livia@cirno.name>
PR-URL: https://github.com/nodejs/node/pull/67695
Refs: https://tc39.es/ecma262/#sec-line-terminators
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2026-11-25 18:20:40 +01:00
René Larch 274c961888 src: rethrow linked binding initializer errors
GetLinkedBinding() reads module.exports after it calls the register
function of a linked binding. If the register function threw, that V8
API call clears the pending exception (PrepareForExecutionScope), so
the error never reaches the caller of process._linkedBinding(), which
gets the empty exports object instead. This affects every linked
binding, including Node-API ones, whose module registration already
rethrows the error of the initializer.

Addons loaded with process.dlopen() are not affected, because DLOpen()
does not call into V8 after the register function. Rethrow the error
before reading module.exports.

Signed-off-by: René Larch <renelarch@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67571
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2026-11-25 18:20:40 +01:00
Yuya Inoue ba3e5c93a3 http2: add writeProcessing to compat response
The HTTP/1 ServerResponse has writeProcessing() to send a 102
Processing response, but Http2ServerResponse does not, so code moving
to the compat API fails with a TypeError when it calls it.

Add writeProcessing([callback]), which sends 102 through
writeInformation() like writeContinue() does.

Refs: https://github.com/nodejs/node/issues/29829
Refs: https://github.com/nodejs/node/pull/67705#issuecomment-7098482431
Signed-off-by: inoway46 <inoueyuya416@gmail.com>
Assisted-by: Claude Code
PR-URL: https://github.com/nodejs/node/pull/67728
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2026-11-25 18:20:40 +01:00
Christian Aurich Zanettini Martins eae0633ec9 sqlite: throw ERR_NO_SQLITE without SQLite support
In builds configured --without-sqlite, passing --experimental-sqlite
exposes node:sqlite, and loading it then fails with
"No such binding: sqlite". Throw ERR_NO_SQLITE instead, like
node:crypto does without OpenSSL.

Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67727
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
2026-11-25 18:20:40 +01:00
Jiawen Geng 1673bbde9a sqlite: guard re-entrant reset of a virtual table cursor
StatementIterator::Return() and SQLTagStore::ResetAndBindStatement()
called sqlite3_reset() without a SteppingStatementGuard. Resetting a
statement with an open virtual-table cursor runs the generator's
finally block, and that JavaScript can reset the same statement
again. SQLite then halts the VM a second time while the cursor slot
still points at the cursor, so xClose frees the same NodeVTabCursor
twice.

Hold the stepping guard across those resets so the re-entrant call
fails with "statement is already being executed" instead of closing
the cursor again. Ignore a second xClose on a cursor that is already
closing.

Assisted-by: Cursor Grok 4.7
Signed-off-by: gengjiawen <technicalcute@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67540
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2026-11-25 18:20:33 +01:00
Matteo CollinaandGuilherme Araújo 8f913a12c8 sqlite: enforce permission model in Database
Database opened database files without consulting the permission
model, so code running with --permission could read and write any
database regardless of --allow-fs-read and --allow-fs-write.

Check read access, and write access unless the database is read-only,
before opening a file-backed database. In-memory databases are exempt.
SQLite also opens journal, WAL and temporary files, and ATTACH and
backup() open further databases, so route every connection through a
VFS shim that checks each path SQLite opens, deletes or probes.

Reject URI filenames that select a VFS, since that would bypass the
shim, and deny ATTACH when SQLite does not pass the filename to the
authorizer.

Refs: https://hackerone.com/reports/3686625
Co-authored-by: Guilherme Araújo <arauujogui@gmail.com>
Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62957
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-25 18:05:55 +01:00
Matteo Collina 4ce7129eb4 module: keep ESM load cache entries in fast mode
Keep per-URL load cache entries in fast-property mode while
   preserving their null prototype.

Assisted-by: Pi
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66276
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
2026-11-25 18:05:55 +01:00
Matteo Collina f5264fad43 stream: forward compose tail error after finish
compose() only listened for 'data' and 'end' on the last stream it was
given. When that stream emitted 'error' after its writable side had
already finished, pipeline() had already removed its own error listener,
so the error reached no listener and was raised as an unhandled 'error'
event, crashing the process.

Forward tail errors to the composed Duplex by destroying it whenever the
tail errors before the composition has been destroyed.

Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67674
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-11-25 18:05:55 +01:00
Guilherme Araújo 610491c77a sqlite: add statement.columnCount getter
Add a getter to `Statement` that returns the number of columns in the
prepared statement's result set, wrapping `sqlite3_column_count()`.

Fixes: https://github.com/nodejs/node/issues/67352
Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67658
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
2026-11-25 18:05:55 +01:00
James M Snell 6dc819754e src: expand --process-timeout output to include workers
When a process is interrupted using `--process-timeout`, the output
would print the resources and stack of the main thread. If the
thing keeping the process alive was a worker thread, or if the
worker thread was interrupted, there was no diagnostic output.

This adds an additional `--process-timeout-worker-stacks` flag
that includes the worker details. We don't necessarily want to
include workers every time because if there's a large number of
workers the output could become quite noisy.

Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Claude
PR-URL: https://github.com/nodejs/node/pull/67712
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
2026-11-25 18:05:55 +01:00
Livia Medeiros 6bbf179c7f test: fix vfs-addon-sequence failing when TMPDIR mounted with noexec
Signed-off-by: LiviaMedeiros <livia@cirno.name>
PR-URL: https://github.com/nodejs/node/pull/67566
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-25 18:05:54 +01:00
Yaroslav Chuhai 23440d4ff2 stream: avoid intermediate Blob in stream/consumers arrayBuffer()
In node:stream/consumers, arrayBuffer() (also used by buffer() and
bytes()) collected stream chunks into a temporary Blob and then read
them back out asynchronously via blob.arrayBuffer(). For binary
streams this copied every chunk twice, allocated an intermediate copy,
and queued a microtask per chunk.

Add a fast path that concatenates chunks directly into a single
ArrayBuffer when all chunks are non-resizable ArrayBuffer-backed
Uint8Arrays (including Buffers) within kMaxLength, falling back to
Blob for all other chunk types. Behavior is unchanged.

Signed-off-by: Yaroslav Chuhai <yaroslavchugai@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67714
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-11-25 18:05:54 +01:00
jakecastelli 8b79be4590 stream: keep data buffered during synchronous flow
The flowing fast path keeps the prefetched chunk off the buffer and
resets `state.length` before each `_read()`. A chunk put on the buffer
by `unshift()` or `push()` from a 'data' listener while a prefetched
chunk was pending was not accounted for, so it was never delivered and
the stream ended with data still buffered.

Move the prefetched chunk onto the buffer before `unshift()` and
`push()` add to it. That keeps the chunks in order and makes the fast
path fall back to `read()`.

Also leave the fast push mode when `_read()` calls `unshift()`,
`read()` or `setEncoding()`. A following `push()` then adds to the
buffer and goes through the decoder instead of overwriting
`state.length` or delivering an undecoded chunk.

Signed-off-by: jakecastelli <38635403+jakecastelli@users.noreply.github.com>
Assisted-by: claude:fable-5.2
PR-URL: https://github.com/nodejs/node/pull/67599
Fixes: https://github.com/nodejs/node/issues/67598
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2026-11-25 18:05:54 +01:00
JuHyeong424 9445cedee3 dgram: fix abort on negative zero buffer size
The size check accepts -0, but the binding asserts IsUint32(),
which V8 reports as false for -0, so setRecvBufferSize(-0) and
setSendBufferSize(-0) abort the process. Coerce the value to +0.

Signed-off-by: JuHyeong424 <wkdwngud963@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67662
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-11-25 18:02:37 +01:00
Ved Chaudhari 10ffe227bf stream: reject operators on empty streams with aborted signal
Stream operators given an already-aborted signal resolved instead of
rejecting when the stream was empty, because the signal was only
checked once a chunk arrived. Check it up front in map() and toArray(),
which the other operators are built on.

Signed-off-by: vedchaudhari <vedc2853@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67637
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2026-11-25 18:02:37 +01:00
James M Snell 8857717d81 test: make test-doc-api-json more robust
The test hard coded the number of deprecated apis
so whenever one is added or removed it always needs
to be updated. This makes the check more robust by
calculating the values on each run.

Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67701
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
2026-11-25 18:02:34 +01:00
Yohannes DestaandAlberto Moretti 13fdf8dea2 fs: report EROFS from recursive mkdir()
A recursive mkdir() that hits a read-only file system treated EROFS like
any unknown error: it stat()ed the missing path and reported the ENOENT
from that instead. Return EROFS straight away, as mkdir() already does
for EACCES, ENOSPC, ENOTDIR and EPERM.

The test uses a read-only file system that is already mounted (listed
in /proc/self/mounts on Linux, the system volume on macOS) and skips
when there is none, since mounting one needs root.

Fixes: https://github.com/nodejs/node/issues/47098
Refs: https://github.com/nodejs/node/pull/48105
Refs: https://github.com/nodejs/node/pull/62725
Co-authored-by: Alberto Moretti <moretti919@gmail.com>
Signed-off-by: Yohannes Desta <yohannesdestagebru10@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67500
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
2026-11-25 18:00:59 +01:00
Node.js GitHub Bot 4aacc4dcae test: update test426-fixtures to bc255a703449b2bc10989772d940df5bf37acf4
PR-URL: https://github.com/nodejs/node/pull/67687
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-11-25 18:00:59 +01:00
Ilyas Shabi 97827de6ab src: speed up heap profile serialization
Signed-off-by: ishabi <ilyasshabi94@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67685
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-25 18:00:58 +01:00
Rafael Gonzaga 6011f571bd src,permission: throw remaining fs errors async
These APIs were missed in https://github.com/nodejs/node/pull/52730.

Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/67037
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2026-11-25 18:00:58 +01:00
Yohannes DestaandNicholas Paun 0fd2bc8717 fs: stat src through symlinks in cpSync() when dereference is set
CpSyncCheckPaths() used symlink_status() for src when dereference was
true and status() when it was false, the reverse of what the option
means. #59681 fixed the same swap for dest but left src as it was.
A symlink to a file passed as src with dereference: true was treated
as a directory, so cpSync() threw ERR_FS_EISDIR unless recursive was
set, while fs.cp() copied the file.

Swap the two calls and drop the check that counted a symlink as a
directory, which status() can no longer return.

Refs: https://github.com/nodejs/node/issues/59168
Refs: https://github.com/nodejs/node/pull/60945
Co-authored-by: Nicholas Paun <npaun@cloudflare.com>
Signed-off-by: yohannesjoya <yohannesdestagebru10@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67340
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
2026-11-25 18:00:58 +01:00
Node.js GitHub Bot d2aaae697a test: update WPT for WebCryptoAPI to 4ba9d1b8e4
PR-URL: https://github.com/nodejs/node/pull/67686
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
2026-11-25 18:00:58 +01:00
dennev e56889e0b9 http: do not reuse expired free sockets
A free socket with an idle timeout is normally destroyed by its timer.
When the event loop is blocked long enough for that timeout to expire,
the timer cannot run, and `addRequest()` can reuse the socket even
though the server may already have closed the connection. This can
cause the request to fail with `ECONNRESET`.

Record when a socket enters the free pool and, before reuse, remove and
destroy a free socket whose idle timeout has expired according to the
timers' clock.

Refs: https://github.com/nodejs/node/issues/54293
Assisted-by: a closed-source coding agent
Signed-off-by: dennev <dennev13@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67292
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2026-11-25 18:00:57 +01:00
Rafael Gonzaga ab5f7b933d path: avoid building error label per argument in resolve
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/66616
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-11-25 18:00:57 +01:00
RafaelGSS faec8f0770 child_process: copy split permission flag values
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/66725
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2026-11-25 18:00:56 +01:00
Hamza Kargin 96554e7a0e stream: retry read after construct when hwm is 0
A read() made while construct() is pending is refused and leaves
needReadable set. After construction, maybeReadMore() does not read
for a non-flowing stream with highWaterMark: 0, so _read() was never
called and consumers such as toArray() or for await waited forever.

Retry the refused read once construction finishes when highWaterMark
is 0.

Fixes: https://github.com/nodejs/node/issues/67668
Assisted-by: AI coding agents
Signed-off-by: Hamza Kargın <hamzakargin@outlook.com>
PR-URL: https://github.com/nodejs/node/pull/67670
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
2026-11-25 18:00:56 +01:00
Paolo Insogna d42740bba0 http: compute body chunk length from decoded bytes
Convert base64, base64url and hex strings to a Buffer before computing
the chunk length, so the announced length matches the bytes written
even when the input contains characters skipped while decoding.

Assisted-By: OpenAI GPT-5.6 Sol <openai/gpt-5.6-sol>
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
PR-URL: https://github.com/nodejs/node/pull/67615
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2026-11-25 18:00:56 +01:00
Rafael Gonzaga 552e89f18d permission: reject empty reference in drop()
An empty reference passed to process.permission.drop() fell through to
dropping the whole scope, while has() treats it as not granted. Throw
ERR_INVALID_ARG_VALUE instead, in both the JS wrapper and the binding.

Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/66732
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2026-11-25 18:00:56 +01:00
Chengzhong Wu 01030e39ff lib: implement source map scopes decoder
Implements the stage 3 https://github.com/tc39/ecma426/blob/main/proposals/scopes.md
proposal decoder. This does not implement the stack trace formatter of
the scopes. The stack trace formatter will be in a follow-up.

Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net>
PR-URL: https://github.com/nodejs/node/pull/67594
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-25 18:00:56 +01:00
Zelalem Habtamu c6f761ea8d os: fix abort on negative zero pid or priority
Fixes: https://github.com/nodejs/node/issues/67648
Assisted-by: Claude Code
Signed-off-by: Zelalem Habtamu <zelalemhab19@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67651
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
2026-11-25 18:00:56 +01:00
Yuya Inoue c2d171507c test: keep response open in http2 response limits test
The server ended the response before the request body arrived, so it
also sent RST_STREAM(NO_ERROR). When that frame reaches the client in
the same read as the rejected headers, the stream is closed by the
peer reset before the client's own reset is sent. On v26.x the request
then closes without an 'error' event and the test times out.

Leave the response open so that only the client resets the stream.

Refs: https://github.com/nodejs/node/pull/67114
Signed-off-by: inoway46 <inoueyuya416@gmail.com>
Assisted-by: Claude Code
PR-URL: https://github.com/nodejs/node/pull/67656
Refs: https://github.com/nodejs/node/actions/runs/44631511460
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2026-11-25 18:00:55 +01:00
Christian Aurich Zanettini Martins faa4039f29 quic: fix abort on handshake failure in connect()
Endpoint::Connect() marked the session as wrapped before sending the
first flight, while JavaScript had no QuicSession for it yet. If the
session closed during that send, for example with ciphers: '', nothing
called destroy() and the CHECK in Session::EmitClose() aborted the
process. Send the first flight before marking the session as wrapped,
so connect() rejects with ERR_QUIC_CONNECTION_FAILED instead.

Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67617
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-11-25 18:00:55 +01:00
Nigro Simone 7f8afae03f src: skip the async id stack when nobody sees it
With no async hook and no executionAsyncResource() user, every
InternalCallbackScope pushed and popped the async ids on the stack, only
for executionAsyncId() and triggerAsyncId() to read the top. Swap the
two ids in place instead: they are all that those two and
process.nextTick() read. executionAsyncResource() is the only reader of
the stack: the scopes that skip it form a chain in AsyncHooks, counted
in a new field, kLazyScopes, and JS asks C++ for the innermost one only
while that count is not zero. The checks for a corrupted stack stay.

Refs: https://github.com/nodejs/performance/issues/24
Signed-off-by: Nigro Simone <nigro.simone@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66511
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-25 18:00:55 +01:00
Hamza Kargin 4d9d24337d fs: read data when highWaterMark is 0
ReadStream.prototype._read() passed the requested size straight to
the end-of-range check, so a size of 0 ended the stream before any
data was read. This happened for createReadStream() with
highWaterMark: 0, and since #66956 for every fs.ReadStream after
stream.setDefaultHighWaterMark(false, 0).

Read 64 KiB, the ReadStream default, when the requested size is 0.

Fixes: https://github.com/nodejs/node/issues/67667
Refs: https://github.com/nodejs/node/pull/66956
Assisted-by: AI coding agents
Signed-off-by: Hamza Kargın <hamzakargin@outlook.com>
PR-URL: https://github.com/nodejs/node/pull/67669
Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-25 18:00:55 +01:00
Mattias Buelens aff078bbdc stream: fix stale byte stream queue size
Re-read the byte controller's queue size before filling each pending
read request. A released BYOB reader can leave a partially filled
pull-into descriptor that is enqueued while a default reader has
multiple pending reads. Caching the queue size causes the loop to
dequeue from an empty queue after fulfilling the first read request.

Add a regression test for one, two, and three pending reads and verify
that any remaining queued bytes are preserved.

Signed-off-by: Mattias Buelens <mattias@buelens.com>
PR-URL: https://github.com/nodejs/node/pull/67499
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-25 18:00:55 +01:00
Nigro Simone 9a1f930065 stream: run a replaced write() in the flowing pipe
pipe() calls dest.write(). The fast path of a flowing pipe hands the
chunks of a source that pushes from _read() to dest._write() directly,
so a write() replaced on the instance or overridden in a subclass no
longer runs. A response that is a Writable, wrapped by compression
middleware, sent a gzip body with uncompressed chunks in it.

Take the fast path only when write() is Writable.prototype.write.

Refs: https://github.com/nodejs/node/pull/66182
Signed-off-by: Nigro Simone <nigro.simone@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66596
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-25 18:00:55 +01:00
Tamir Duberstein 58ac3ca29f test: check the TLS server name on address-family fallback locally
The TLS address-selection test connects to nodejs.org twice. A reset
can fail the test before the handshake completes, and the addresses
returned by DNS determine whether the client ever tries a second one.

Run a TLS server on IPv4 loopback. With address-family selection
enabled, return IPv6 loopback first so the client has to switch TCP
handles. Check which server name reaches the server and keep certificate
verification enabled on the client.

Refs: https://github.com/nodejs/node/issues/46679
Assisted-by: Codex
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67595
Reviewed-By: Tierney Cyren <hello@bnb.im>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-11-25 18:00:55 +01:00
Christian Aurich Zanettini Martins ee6fd3bbc8 fs: fix abort on negative zero write length
`validateOffsetLengthWrite()` accepts -0 as a length, but V8 does not
represent -0 as an Int32 value, so the `IsInt32()` check in the binding
aborted the process in `fs.write()`, `fs.writeSync()` and
`filehandle.write()`.

Coerce the validated length to an int32 before the call, as `fs.read()`
already does.

Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67524
Refs: https://github.com/nodejs/node/pull/65888
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2026-11-25 18:00:54 +01:00
Paolo Insogna bed62887dd https: encode all TLS fields in agent names
`https.Agent#getName()` joined several TLS options with `:` without
encoding them, so a value containing `:` could shift into the next field
and produce the same name as a different set of options. A `DataView`
passed as `dhparam` was also reduced to its type name.

Encode the remaining string, boolean, number, buffer and array valued
options, including `sigalgs`, with `getTlsOptionKey()`, which prefixes
the type and the length, like the options that were already encoded.

Assisted-By: OpenAI GPT-5.6 Sol <openai/gpt-5.6-sol>
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
PR-URL: https://github.com/nodejs/node/pull/67641
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-25 18:00:54 +01:00
Jiawen Geng c9a7b131f1 sqlite: skip query trace while an exception is pending
Database::TraceCallback published sqlite.db.query from SQLite's
profile callback without checking for a pending JavaScript exception.
SQLite runs that callback from sqlite3_step() when a statement fails
and from sqlite3_reset(), so a throwing SQL function or an
out-of-range integer conversion called subscriber JS while an
exception was already set. Debug builds abort in V8's Invoke, and
release builds drop the original error or replace it with an empty
ERR_SQLITE_ERROR.

Return before publishing when the isolate has a pending exception or
JavaScript cannot be entered.

Assisted-by: Cursor Grok 4.7
Signed-off-by: gengjiawen <technicalcute@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67538
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-25 18:00:54 +01:00
Jiawen Geng 00480cf72e sqlite: finalize statements prepared during close
Database::FinalizeStatements() range-iterates statements_ and then
clears the set. Finalizing a statement with an open virtual-table
cursor runs the generator's finally block, which can prepare a new
statement and insert it into the set being iterated. That statement
is never finalized, so it keeps running after close() releases the
connection, and run() then dereferences a null connection.

Erase each statement before finalizing it and continue until the set
is empty, so statements created from that JavaScript are finalized
before the connection is released.

Assisted-by: Cursor Grok 4.7
Signed-off-by: gengjiawen <technicalcute@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67539
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-25 18:00:54 +01:00
Livia Medeiros 9a5955a154 lib: replace SafePromiseAll with SafePromiseAllReturn*
`SafePromiseAllReturnArrayLike` and `SafePromiseReturnVoid` are
safer, faster alternatives to `SafePromiseAll`. The latter should
be used only when we expose returned value directly to userspace.

Signed-off-by: LiviaMedeiros <livia@cirno.name>
PR-URL: https://github.com/nodejs/node/pull/67602
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-25 18:00:54 +01:00
James M Snell cd7da920c5 stream: lighten single-chunk stream/iter broadcast()/share() batches
As for push() writes, broadcast() writes and the source batches share()
buffers were each kept as a BatchEntry with an array of views, also for
the common case of a single chunk, and broadcast's write() first wrapped
its chunk in an array.

createEntry() returns the chunk's FixedByteView for a single-chunk batch
and a BatchEntry otherwise; validateBatchEntry() and splitBatchEntry()
take either. broadcast() and share() buffer their batches with it, and
push()'s writev() too.

Allocation per chunk, two consumers, 16-byte chunks:
- share(), sync source: 722 -> 626 bytes; async source: 1944 -> 1848
- Broadcast.from(), sync source: 868 -> 752 bytes; async: 1873 -> 1783

testBufferedBatchViewResizeRejected checks that a view resized in a
buffered multi-chunk batch still rejects the read, for broadcast() and
share(). It also passes before this change.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66504
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-25 18:00:53 +01:00
James M Snell fdedf0a8a0 stream: skip batch entry for single-chunk stream/iter push() writes
Every push() write allocated, before the chunk was buffered, a [chunk]
array, a BatchEntry with a views array, and a FixedByteView; a read of
several buffered writes then validated each into an array of its own and
copied those into the batch it returns. That was most of what a write
costs (192 of 223 bytes for a 16-byte chunk, without pointer
compression).

A single-chunk write() or writeSync() now buffers the chunk's
FixedByteView itself, which has the byteLength a BatchEntry has; entries
are told apart by `views`, which a FixedByteView lacks. writev() keeps
its BatchEntry. A read validates the buffered views straight into the
batch it returns, and a pending write is checked without collecting its
chunks. The checks are the same as before.

Allocation per write (16-byte chunks; the consumer reads the buffered
writes as they come):
- writeSync(), falling back to write(): 223 -> 70 bytes
- await write(): 397 -> 246 bytes
- strings (pooled encoding): 315 -> 185 bytes

testBufferedEntriesReadTogether checks that single-chunk and batch
writes read together are delivered in order, and that a view resized
among them rejects the read. It also passes before this change.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66504
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-25 18:00:53 +01:00
James M Snell 918c34878d stream: avoid a promise per stream/iter from() read in pipelines
A pull() pipeline, pipeTo() with a signal and the consumers with a
signal reject their own pending pull, pipe or read when they are
aborted, and ignore the read of the source that is still pending then.
Yet they read a from() async source with its cancellable next(), which
gives every read a promise of its own so that a cancellation can reject
it at once: about 230 bytes per batch, for a rejection nobody waits for.

They now read such sources with kNextUncancellable, as pipeTo() without
a signal already did, when nothing but stream/iter code waits for the
reads: always for pipeTo() and the consumers, and for pull() pipelines
without stateful transforms. A stateful transform's generator waits for
the source in user code, so with one the reads stay cancellable and its
finally block still runs at once.

What makes this possible is that a cancellation now releases a pending
kNextUncancellable read instead of waiting for it: the normalization
ends, the source is closed at once (as for a cancelled next(), errors
ignored), and the operations queued behind the read, such as the
return() that cancelled it, run. The read settles when the source's
next() does, rejecting with the cancellation reason, and is ignored. A
pipeline stopped with return() or throw() while a pull is pending closes
its (stateless) transform layers without waiting for them, since they
wait for that read.

Allocation per batch, 16-byte chunks, async source:
- pipeTo() with a signal: 967 -> 738 bytes (as without a signal)
- pull() with one transform: 1518 -> 1289 bytes
- pipeTo() with a signal and one transform: 1829 -> 1601 bytes

test-stream-iter-abort-pending-read.js checks, for pull(), pipeTo() and
bytes(), with and without transforms and stopped by a signal, return()
or throw() while the source's next() is pending, that the call rejects
at once, the source is closed before that next() settles, and nothing
happens when it does. It also passes before this change.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66504
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-25 18:00:53 +01:00
James M Snell a6e8812c58 stream: keep stream/iter broadcast waiters in reused lists
Broadcast notified waiting consumers by swapping #waiters for a new
SafeSet on every notification, so that a consumer re-waiting while being
notified was not processed twice. That happens for every chunk that
consumers wait for, and each Set operation allocates: the new Set, the
for...of iterator, and clear() or deleting the last entries (120-150
bytes each).

The waiters are now kept in two RingBuffers that are swapped back and
forth; the notified list is drained with shift() and cleared, keeping
its storage. A nested notification while the spare list is in use gets a
new one. A consumer detaching removes itself with indexOf()/removeAt(),
as it did with delete(); it is in the list at most once, as before.

Broadcast.from() fan-out, async source, two consumers, 16-byte chunks:
2036 -> 1873 bytes allocated per chunk.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66504
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-25 18:00:53 +01:00
James M Snell 17504260d7 stream: do not keep stream/iter from() sync sources busy for a tick
The iterator of from() over a sync iterable stayed busy until the
microtask after every result it produced synchronously, as an async
generator stays busy until the tick after a yield, so that a call made
synchronously after one was queued behind it. That cost a microtask per
batch, also when nothing was ever queued.

Settle each operation when its result is known instead, as the
normalizer of async sources does: a call made after one that finished
synchronously now runs at once, and calls queued while one was in
progress, such as behind a value normalized asynchronously, still run
a microtask later. Only calls made back to back without awaiting are
affected: a second next() reads the source during the call, and a
return() made after it no longer cancels it, as it did when it was
still queued. The other iterators of from(), for values and async
sources, already behaved this way. The queue's release() is no longer
used.

Iterating from() over a sync source yielding one-chunk batches is
about 1.38 times faster, now on par with a ReadableStream, and with
64-chunk batches about 7% faster.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66504
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-25 18:00:53 +01:00
James M Snell e6995cfeca stream: read a single stream/iter merge() source without a generator
merge() of a single source read it with an async generator, a layer
for every batch, on top of the abortable wrapper when a signal was
given.

Without a signal, read the source with MergeSourceIterator: calls to
next() go to the source's iterator, which from() makes queue them as an
async generator does, and return() and throw() wait for the last next()
before closing the source, as the generator queued them. With a signal,
return the iterator of the abortable wrapper, which already rejects a
pending read when the signal aborts, closes the source and then ends.
As the generator did, an abort before the first read now ends the
iteration without opening the source.

Iterating merge() of a single source of 16-byte chunks one per batch is
about 1.7-2.2 times faster without a signal, and 1.5-1.7 times faster
with one.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66504
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-11-25 18:00:53 +01:00