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>
Import attributes were created in C++ with v8::Object::New() and a
null prototype, once per module request and once per import() call.
Every import() call also created a `{ __proto__: null }`
diagnostics_channel context, which was discarded when module.import
had no subscribers. V8 creates all of these in dictionary mode.
Build the attributes from an ordinary object with its prototype set to
null, and only create the trace context when there are subscribers.
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67554
Refs: https://github.com/nodejs/node/pull/67552
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@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>
Using `__proto__: null` on objects will properties immediately
puts them into the slower DictionaryProperties mode. Using a
`__proto__: { __proto: null }, ...` pattern, however, keeps
the objects in FastProperties mode.
Technically this is an observable change since calling
`Object.getPrototoTypeOf(...)` some of these will no longer
return `null`. So a decision needs to be made about whether
these types of changes are `semver-major` or not.
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66678
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@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>
Document which digest and MAC options apply and how output lengths
work. Clarify signature contexts and distinguish required parameters
from optional defaults in Web Crypto.
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>
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>
Build exposed MAC parameters from one option table and their advertised
types. Keep binary octet values and terminated UTF-8 strings.
Share sign/verify initialization and replace padding and salt length
presence flags with optional values. Pass context parameters during
initialization and retain backend-specific handling.
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>
V8 keeps objects created from `{ __proto__: null }` literals, and from
v8::Object::New() with names and values, in dictionary mode for their
whole life. The module loader created such objects on every require()
of a builtin and every import(), and kEmptyObject, the cached ESM
resolve results and the requests from getModuleRequests() were all
in dictionary mode as well.
Use classes with a null-prototype prototype for the per-call objects,
null the prototype of plain literals for the long-lived ones, and
build module requests from a DictionaryTemplate.
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67552
Refs: https://adventures.nodeland.dev/archive/optimizing-objects-with-null-prototypes/
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Chengzhong Wu <legendecas@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>
readBig(U)Int64{LE,BE}() and writeBig(U)Int64{LE,BE}() assembled and
split values with BigInt arithmetic, allocating intermediate BigInts on
every call. Copy the bytes through BigInt64Array and BigUint64Array
views over the existing 8-byte scratch buffer instead, as the double
accessors already do.
Range and bounds checks are unchanged, and the value is masked with
`& -1n` before the store so non-BigInt values still throw the same
TypeError instead of being coerced by the typed array.
benchmark/buffers/buffer-read.js now uses the value it reads. The
loop discarded it, which let V8 remove side-effect-free reads
altogether.
Assisted-by: claude:opus-5.5
Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day>
PR-URL: https://github.com/nodejs/node/pull/67549
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@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>
Chromium's build no longer lists the Rust std backtrace crates in
`stdlib_files`, because its own std is built without backtrace support.
The system Rust toolchain used by `make-v8.sh` ships a std built with
it, so linking mksnapshot fails with undefined `gimli` and `addr2line`
symbols. Pass the crates through `added_rust_stdlib_libs`, which
replaces the libadler patch of `build/rust/std/BUILD.gn`.
Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net>
PR-URL: https://github.com/nodejs/node/pull/67070
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Richard Lau <richard.lau@ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
V8 now starts the `v8_internal_headers` source list with `sources = []`.
The GN scraper skips the empty list and matches
`v8_compiler_sources = [` instead, so every dependent of
`v8_internal_headers` compiled all of the compiler sources again. That
breaks the shared library link with duplicate symbols. Match the
`sources += [` list that holds the headers.
Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net>
PR-URL: https://github.com/nodejs/node/pull/67070
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Richard Lau <richard.lau@ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>