CustomBufferJSListener keeps only the raw address (uv_buf_t) of the
user-supplied onread buffer, without retaining the backing store. If
application code transfers (and thereby detaches) that buffer during the
onread callback, for example by enqueuing a view into a byte
ReadableStream, the backing store is moved away from under the listener
and the raw address is left dangling. Reading subsequent peer data into
that address then corrupts memory the application owns, and if the
backing store is later released, it becomes a use-after-free.
Retain the backing store in CustomBufferJSListener so the raw address
never dangles, and stop reading when the onread callback detaches the
buffer so the stale address is not handed back to libuv.
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67542
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
The tests started one request chain per CPU, each issuing a new request
on every event loop turn until the first response arrived. On a loaded
macOS host this put more than 128 connections in flight, overflowing
the listen queue. The kernel then drops an incomplete connection and
answers its final ACK with a RST, so the client fails with
`connect ECONNRESET`.
Use a fixed number of concurrent requests and a fixed total instead.
Drive-by: the error handler in test-gc-http-client-onerror rethrows,
fix the comment that says it does nothing.
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67607
Refs: https://github.com/nodejs/node/issues/41399
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
V8 background jobs, such as concurrent Sparkplug and Maglev compiles,
can run into the heap limit. They then post a GC request to the main
thread and park in CollectionBarrier::AwaitCollectionBackground()
until the main thread collects garbage or the isolate is torn down.
process.exit() does neither. DefaultProcessExitHandlerInternal()
calls DisposePlatform() while the isolate is still alive and not
running JS, and NodePlatform::Shutdown() joins the worker threads.
A worker that is parked at that point never wakes up, and the join
hangs forever.
Pass the exiting isolate down to NodePlatform::Shutdown(). While the
workers finish their current tasks, the main thread checks every
10ms whether a foreground task was posted for that isolate. If so,
it drops the queued tasks, which would never run on this path, and
performs a GC so that the parked workers can finish. Normal exits
dispose the isolate before the platform and are not affected.
Fixes: https://github.com/nodejs/node/issues/64274
Signed-off-by: Manzoor Wani <manzoorwani.jk@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66171
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
V8 cannot collect block coverage for functions that are deserialized
from the code cache, so it only reports how many times each of them
ran. With a warm compile cache, branches that never ran inside those
functions are reported as covered, and tools that merge reports from
several processes can report functions that ran as never run.
The documentation recommended turning the cache off by hand. Do it
automatically when coverage collection starts with the process, through
NODE_V8_COVERAGE or --experimental-test-coverage.
The compile cache tests stop propagating NODE_V8_COVERAGE to the
processes they spawn, so that they keep working when the test suite
itself runs with coverage.
Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67120
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Cover binary and empty digest customization, incompatible parameter
types, and MAC descriptor selection with a shared test provider.
Check UTF-8 termination for byte inputs.
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/67565
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Resolve the exposed digest options against provider descriptors and
construct UTF-8 or octet strings according to their advertised types.
Keep binary values intact for octet strings and reject NUL bytes for
UTF-8 strings.
Share hash initialization and one-shot input/output handling while
retaining the plain digest fast paths and XOF length checks. Probe RSA
implicit rejection without changing its context.
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/67565
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
run() and get() reset a cached statement pointer on exit. Throwing an
error can run an Error.prototype setter that closes the database and
frees it. Reset through the Statement, which Finalize() clears.
Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67557
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Exposes the internal `guessHandleType` function as
`guessFileDescriptorType`, which can be used to see if a handle has a
specific type, regardless of the OS it is on.
This helps out with detecting, for example, if standard input is piped
into the process, instead of relying on file system calls.
Refs: https://github.com/nodejs/node/issues/57603
Signed-off-by: Vlad Frangu <me@vladfrangu.dev>
PR-URL: https://github.com/nodejs/node/pull/58060
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Aviv Keller <me@aviv.sh>
Previously this could fail - not having read 'end' when the close
arrived was treated as a premature close error for finished() and
related APIs, even though the body data was cleanly ended and complete.
We now check whether there is a clean end buffered. If so, we wait
until it's read before evaluating whether the stream ended cleanly.
Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67553
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
If the stream is destroyed right after sendHeaders(), nghttp3 still has
the response headers queued. On the next write it asks for the removed
stream's body, the read callback fails, and the whole session closes
without notifying the peer.
In an HTTP/3 session, before clearing nghttp3's pointer to a stream when
the stream is destroyed, shut down nghttp3's writes for that stream so
that other requests can continue to complete.
Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ethan Arrowood <ethan@arrowood.dev>
PR-URL: https://github.com/nodejs/node/pull/67446
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
setHeader() stored the caller's array and that led to mutation
issues with appendHeader() pushing new values into it. The caller
would see values added to that array, and if the array was frozen
appendHeader() would throw a TypeError.
This fix copies the array value instead so the response instance
owns it completely. getHeader() still return the stored array.
It also applies the same change to HTTP2 compat api.
Fixes: https://github.com/nodejs/node/issues/67526
Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ethan Arrowood <ethan@arrowood.dev>
PR-URL: https://github.com/nodejs/node/pull/67528
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
In the HTTP/1 server, writeContinue(), writeEarlyHints() and
writeInformation() accept a callback that is called once the response
has been written to the socket. The HTTP/2 compat versions did not, so
code moving to the compat API had its callback ignored.
Accept an optional callback in http2stream.additionalHeaders() and in
the three compat methods. The request for the HEADERS frame is tracked
until nghttp2 serializes the frame, and completed together with the
write to the underlying stream that carries it.
Signed-off-by: inoway46 <inoueyuya416@gmail.com>
Assisted-by: claude:opus-5.5
PR-URL: https://github.com/nodejs/node/pull/67470
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Tim Perry <pimterry@gmail.com>
The mappings parser detects a segment that has only a generated column
by peeking at the next character. At the end of the mappings string the
peek returns an empty string, which is not a separator, so a final
generated-only segment is decoded with phantom zero deltas and inherits
the source, line, and column of the segment before it. With
--enable-source-maps, stack frames in code after the last mapped
segment are then attributed to the last mapped source.
Check for the end of the string before reading source fields.
Signed-off-by: Jacky Zhao <j.zhao2k19@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66264
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
There can be more than one garbage collection triggered by
one gc() call and it's not controllable by Node.js.
Update the assertion to check that at least one expected
GC is there, but don't check that there aren't more.
Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67547
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
RealFSProvider.mkdirSync()/mkdir() forwarded the raw fs.mkdirSync()
result, which for { recursive: true } is the absolute backing-directory
path of the first created directory. VirtualFileSystem#toMountedPath()
then joined the mount point with it, producing <mount>/<root>/a instead
of <mount>/a, so the returned path failed fs.existsSync().
Reuse the existing #resolvedToVfsPath() helper (as realpath does) to
translate the result back to a provider-relative VFS path, matching
MemoryProvider.
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: opencode
PR-URL: https://github.com/nodejs/node/pull/66221
Fixes: https://github.com/nodejs/node/issues/66220
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Only spread own enumerable properties for URL instances created by this
realm's URL constructor. Duck-typed objects accepted by isURL() can no
longer smuggle connection options (socketPath, method, headers, agent)
into a request.
This fixes a footgun where a hostname-validated http.request() could be
redirected to a Unix socket (e.g. the Docker daemon) via a URL-shaped
object, bypassing hostname-based SSRF checks. Extending a genuine URL
object with extra options is preserved.
Refs: https://github.com/nodejs/node/pull/46989
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67454
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Since stat() started going through raceWithSignal(), permission
errors from fsPromises.stat() have had no stack frames. The binding
rejects them right away, and raceWithSignal() returned that promise
from an async function without awaiting it, so nothing was awaiting
it yet when the stack was captured.
Return the promise as is when there is no signal, so stat() awaits
it directly again.
Refs: https://github.com/nodejs/node/pull/63143
Signed-off-by: vedchaudhari <vedc2853@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67525
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Destroy established TLS sockets on fatal errors so pending writes
cannot prevent HTTP/2 session cleanup from completing. Defer closing
until after error handling to preserve connection details for listeners.
Add regression coverage for standalone TLS socket closure and HTTP/2
cleanup with default and custom TLS connections.
Fixes: https://github.com/nodejs/node/issues/67213
Signed-off-by: inoway46 <inoueyuya416@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/67215
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
Clear a deferred socket handle before invoking close listeners. TLS has
already freed its SSL state at this point, so retaining the handle lets
getProtocol() access a null SSL pointer and crash the process.
Keep connection details available during tlsClientError and add coverage
for querying the protocol after a failed handshake closes the socket.
Signed-off-by: inoway46 <inoueyuya416@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/67215
Fixes: https://github.com/nodejs/node/issues/67213
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
For now this changes very little, but offers an option to directly
control whether this is supported. In future, this will default to
'false' (disabling by default) and eventually be mostly removed,
except opt-in client support for accepting renegotiation requests
from servers.
Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67532
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
The maxPayloadSize option was copied into ngtcp2's
max_tx_udp_payload_size unchecked. ngtcp2 requires 1200 to 65527 and
only asserts it, so in a release build 0 gave the congestion controller
an empty initial window and the process died with SIGFPE in
ngtcp2_cc_cubic_init() when the connection was created. Values from 1
to 1199 were accepted and the session was destroyed before it opened.
Reject values outside that range when the session options are parsed,
for both connect() and listen().
Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67531
Refs: https://github.com/nodejs/node/pull/65827
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: James M Snell <jasnell@gmail.com>
SEA binaries built with "useVfs" can now load source maps from the
bundled assets (or the "vfsArchive" archive) and apply them to stack
traces and error output, because fs reads are routed through the virtual
file system mounted by the SEA.
Add two tests covering the inline-assets and zip-archive VFS paths, each
asserting that findSourceMap() resolves against the mount point and that
a thrown error's frame and source line are remapped to the original
source. Also document how to enable and bundle source maps in a SEA.
Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67503
Reviewed-By: Philipp Dunkel <pip@pipobscure.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
With process isolation, the `--test-rerun-failures` state file is
written by the parent process, which numbered tests sharing a location
across all test files, while each child process numbers them within
its own file. A test defined in a helper used by several test files
was therefore looked up in a slot belonging to another file, and a
failing test could be replayed as passed without running.
Prefix the identifier of a test defined outside of its entry file with
the entry file when tests run in per-file child processes, and build
the identifier with the same helper on both sides.
Signed-off-by: Moshe Atlow <moshe@atlow.co.il>
PR-URL: https://github.com/nodejs/node/pull/67512
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
The location of a test file run in a child process was resolved
against `process.cwd()`, so `run()` reported a wrong `entryFile` for
relative paths when called with a different `cwd`.
Signed-off-by: Moshe Atlow <moshe@atlow.co.il>
PR-URL: https://github.com/nodejs/node/pull/67512
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
fs.opendir() only checked options.bufferSize in the Dir constructor,
which runs from the completion callback of the native opendir call.
An invalid value was thrown from there, so it could not be caught and
the process exited. fs.promises.opendir() is built on fs.opendir() and
had the same problem.
Check bufferSize before starting the native call, so fs.opendir()
throws to the caller and fs.promises.opendir() rejects.
Fixes: https://github.com/nodejs/node/issues/67182
Signed-off-by: Yohannes Desta <yohannesdestagebru10@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67183
Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>