The MIME regex used for data: URLs could backtrack super-linearly on a
malformed URL lacking a ',' separator. Make the optional parameter
group anchored on ';' so it cannot overlap with the media-type group.
Adds a benchmark (esm/get-data-protocol-format) parameterized over
path length, so a backtracking regression shows up as an ops/sec
cliff instead of a wall-clock assertion in a test, per review.
Fixes: https://github.com/nodejs/node/issues/61904
Signed-off-by: skdas20 <skdas5405@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/61951
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
When using the dot reporter with coverage enabled, coverage threshold
failures and coverage reports were not printed, only an exit code was
returned. This made it impossible to know why the test run failed.
This change adds handling for test:diagnostic and test:coverage events
to the dot reporter, matching the behavior of the spec reporter.
Fixes: https://github.com/nodejs/node/issues/60884
Signed-off-by: mag123c <diehreo@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/61423
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
Parse query strings with indexOf instead of a per-character state
machine, skip ToString when values are already strings, cache
toString() until the list mutates, and join serialized pairs.
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
Assisted-by: Cursor
PR-URL: https://github.com/nodejs/node/pull/65363
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Aviv Keller <me@aviv.sh>
When `fs.cp`/`fs.cpSync` is called with both `verbatimSymlinks: true`
and a `filter` function, directory symlinks were incorrectly created
as file symlinks on Windows.
Without a `filter`, cp takes the C++ fast path (`cpSyncCopyDir`) which
uses `std::filesystem::copy_symlink()` and preserves the symlink type
automatically. With a `filter`, the JS fallback calls `symlinkSync`/
`symlink` without a `type` argument. On Windows, that causes the type
to be auto-detected by stat-ing the resolved target at the destination,
but during a recursive copy the target directory may not exist yet at
the destination (e.g. `linked/` is copied before `packages/` in
alphabetical order). The stat fails and `type` falls back to `'file'`,
producing a file symlink in place of a directory symlink.
Detect the symlink type from the source (which always exists) via
`internalModuleStat(src)` and pass it explicitly to the `symlinkSync`/
`symlink` call sites. `onLink` already computed `srcIsDir` for
subdirectory validation; hoist that computation above the early-return
paths and thread the derived `symlinkType` through `copyLink` as well.
Both the sync (`cp-sync.js`) and async (`cp.js`) implementations are
fixed.
Add two regression tests that copy a tree containing a relative
directory symlink with `verbatimSymlinks: true` and a `filter`
function, then assert the destination link still resolves as a
directory.
Fixes: https://github.com/nodejs/node/issues/62653
Signed-off-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/62654
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Every promise-based fs operation eagerly allocated two AliasedBuffers
(a stats array and a statfs array) at request creation, although only
stat-family resolutions ever read the first and only statfs() reads
the second. Each allocation is an ArrayBuffer, a TypedArray and a
strong v8::Global. The callback path has no equivalent cost since it
resolves through a shared global array.
Construct the arrays lazily in ResolveStat()/ResolveStatFs() instead.
Once created the lifetime is unchanged, so deferred continuations
still read from request-owned memory.
Improves fs/promises throughput under concurrency: writeFile +53%,
stat +26%, readFile +22% at 64 in-flight operations on tmpfs, with
callback paths unchanged.
Signed-off-by: Sam Attard <sattard@anthropic.com>
PR-URL: https://github.com/nodejs/node/pull/63886
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Contexts that are not deserialized from the built-in snapshot -- worker
threads, and the main context of embedders that create their own
isolate or of `node --no-node-snapshot` -- compile (with the code cache
at best) every builtin the bootstrap touches, so each eagerly required
builtin is startup time (~0.15-0.4 ms apiece). A number of them are only
required eagerly so that they end up in the snapshot, or for features
the bootstrap path never uses.
Load lazily what those paths do not need:
- is_main_thread.js: preload util, url, the ESM loader (translators,
resolver, module_job/map, source maps, node:module, vm modules, mime,
data_url, the TypeScript stripper), internal/blob and
internal/dns/utils only while building a snapshot; they load on first
use otherwise.
- fs: internal/blob (+ internal/encoding and its tables) is only used
by fs.openAsBlob().
- internal/url: internal/data_url (+ internal/mime) is only used by the
Buffer-returning file URL helpers.
- internal/process/execution, the CommonJS loader, esm/translators and
esm/load: the TypeScript stripper and data: URL helpers are only
needed for TypeScript sources / data: URLs.
- pre_execution: internal/dns/utils (+ internal/net) is only needed up
front to validate an explicit --dns-result-order or to register the
resolver's snapshot serializer; the default order becomes the
variable's initializer.
- internal/worker: event_loop_utilization and error_serdes are only
needed once a sub-worker's ELU is read or it reports an error.
- worker_threads: `locks` is defined lazily, like util's lazy exports.
Main-thread startup with the snapshot is unchanged (the same modules
are preloaded into it; the bootstrap-modules test lists are adjusted).
A bare worker compiles 95 -> 83 builtins (cold start -5%); without the
snapshot an empty CommonJS entry point compiles 76 -> 59 builtins and an
empty ES module entry point 76 -> 69.
Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65329
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
Commit Queue failure comments hid the actionable reason inside the
collapsed landing transcript.
Surface the reason and retry instructions before the full output. Add
specific guidance for a missing multi-commit policy and explicit reasons
for push and squash-merge failures.
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65433
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Use BoringSSL's current RSA and DH validation results instead of
maintaining backend-specific prechecks and collapsing key errors.
Report negotiated TLS groups and the documented zero security level
through BoringSSL's compatibility APIs.
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65423
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
BoringSSL implements OPENSSL_zalloc and BN_secure_new and provides
compatible secure heap status stubs. Use the common code paths.
Remove ClientHello helpers left unused by the early callback migration
and require the fixed ML-KEM private-key import error.
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65423
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
The test verified ipv6Only by connecting to the IPv4 side of an
ephemeral port and expecting ECONNREFUSED, but it never reserved that
IPv4 port. Under parallel execution another test could occupy it,
making the connection succeed instead of being refused.
Run the test sequentially with a fixed common.PORT so it no longer
competes with other tests for the same port, matching the fix already
applied to the sibling cluster variants.
Fixes: https://github.com/nodejs/node/issues/64172
Signed-off-by: sangwook <rewq5991@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/64173
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The fix and approach are from #64491 by Shivay-98; this reopens it to
get it landed, since the original stalled awaiting requested changes.
`Socket.prototype._unrefTimer` and `Socket.prototype._destroy` both walk
the `_parent` chain with a strict `!== null` check. During connection
teardown a socket's `_parent` can be left `undefined` (for example a TLS
socket layered over another stream), so the loop steps onto `undefined`
and reads a property off it, throwing a TypeError:
Cannot read properties of undefined (reading 'Symbol(timeout)')
from an uncaught I/O callback and crashing the process.
Using a nullish (`!= null`) check terminates the walk on both `null` and
`undefined`.
[petter@hightouch.io: apply the same fix to the identical loop in
`_destroy`, which the original regression test already exercised via
`destroy()`; add direct unit coverage for both paths.]
Fixes: https://github.com/nodejs/node/issues/64490
Refs: https://github.com/nodejs/node/pull/64491
Signed-off-by: Petter Häggholm <petter@hightouch.io>
PR-URL: https://github.com/nodejs/node/pull/64644
Fixes: https://github.com/nodejs/node/issues/64490
Refs: https://github.com/nodejs/node/pull/64491
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
c4b755ee00 tracks the statements currently being stepped and rejects
reentry into them, but the guard is established inside the execution
helpers, after the entry point has already reset the statement and
bound its parameters. Binding reads properties off the supplied
object, so a named-parameter getter runs JavaScript in that window.
Reentering the same statement there resets it a second time and, for
iterate(), hands out a second iterator; both iterators record the
same reset generation, so neither is invalidated and they interleave
rows from one virtual machine.
Establish the guard at the four StatementSync entry points instead,
before the reset, so it spans binding as well as stepping. The
existing guards inside the helpers are left in place; the stepping
set is a stack, so the nested acquisition is balanced.
Signed-off-by: Trevor Burnham <trevorburnham@gmail.com>
Assisted-by: claude:opus-5
PR-URL: https://github.com/nodejs/node/pull/65294
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
A portable compile cache is meant to be reused wherever the same module
layout is found, which includes being generated once (at build time,
say) and shipped read-only with an application for whoever runs it. On
platforms with uids the cache subdirectory is suffixed with the uid of
the user who created it, so such a cache is only ever found by that one
user. Omit the suffix in portable mode: a user who cannot write to the
directory still reads it, and a failed write is only a cache miss.
Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65293
Reviewed-By: James M Snell <jasnell@gmail.com>
When `mock.module()` targets a package whose `exports` field maps
`import` and `require` to different files, the ESM resolver and the
CJS resolver disagree on the resolved path. Only the ESM path was
registered in `mockMap`, so `require()` of the mocked specifier
bypassed the mock and loaded the real CJS module.
Resolve the specifier through `Module._resolveFilename` from the
caller's directory in addition to the existing ESM resolution. When
the two paths differ, register the CJS path as a second key in
`mockMap` and invalidate `Module._cache[cjsPath]`, restoring it on
`restore()`. Single-resolution packages keep their existing behavior.
Fixes: https://github.com/nodejs/node/issues/58231
Signed-off-by: Maruthan G <maruthang4@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62943
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Jacob Smith <jacob@frende.me>
Passing a directory to `node --test` (e.g. `node --test tests`) matched
the directory itself as a glob pattern and then tried to run it as a
test file, failing with MODULE_NOT_FOUND. Before glob patterns were
supported, a directory argument was searched for test files within it.
Expand a pattern that resolves to a directory into a search for the
default test files inside it. Despite the report framing this as
Windows-only, it reproduces on every platform: it is a plain
regression from when directory arguments stopped being searched.
Fixes: https://github.com/nodejs/node/issues/64555
Signed-off-by: Paul Bouchon <mail@bitpshr.net>
PR-URL: https://github.com/nodejs/node/pull/64637
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
The example under "Setting security levels" does not run. The client
sets `maxVersion: 'TLSv1'` while its `minVersion` stays at the
`tls.DEFAULT_MIN_VERSION` default of `'TLSv1.2'`, so no version overlaps
and the connection fails with ERR_SSL_NO_PROTOCOLS_AVAILABLE. Setting
the client's `minVersion` is not enough on its own: the handshake then
fails with an alert 40, because `createServer` is given no key or
certificate and the server has no shared cipher.
Set `minVersion` on the client, add the key and certificate placeholders
and the openssl recipe that the other sections using them already carry,
pass the server certificate as the client's `ca`, and use port 8000 like
the rest of the file. The section now runs from an empty directory and
prints "Client connected with protocol: TLSv1".
Signed-off-by: Julian Soreavis <julian.soreavis@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65391
Fixes: https://github.com/nodejs/node/issues/60569
Refs: https://github.com/nodejs/node/pull/60571
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
An iterator can leave a statement active between sqlite3_step() calls.
Finalizing that statement from an authorizer callback can release its
locks and change the outcome of the statement being authorized.
Reject close() and Symbol.dispose when the statement is busy and the
connection is in an authorizer callback. Continue allowing idle
statements to be finalized.
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: codex:gpt-5.6-sol
PR-URL: https://github.com/nodejs/node/pull/65369
Fixes: https://github.com/nodejs/node/issues/65368
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
The merge-commit job used `make -j4`, which skips configure. After
node.gyp or generated sources change, that can leave the comparison
binary unlinked against new files. `make build-ci` re-runs configure
first, matching the base-build step.
Assisted-by: Grok
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
PR-URL: https://github.com/nodejs/node/pull/65362
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Mkdtemp() allocated the template buffer as `length + strlen("XXXXXX")`,
leaving no room for the terminating NUL byte. For a single-byte prefix
long enough to force the heap allocation path (length + 6 > the
stack-buffer threshold), the terminating NUL was written one byte past
the end of the buffer -- a 1-byte heap-buffer-overflow flagged by
AddressSanitizer.
Allocate room for the terminating NUL, copy the suffix, and use
SetLengthAndZeroTerminate to set the correct length and write the
terminator, following the MaybeStackBuffer paradigm used elsewhere in
this file.
Signed-off-by: frandle331-yh <s1240100@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/64770
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
This function returns a negative error code on error.
When it does so, the `value_str` pointer will remain uninitialized
and cause a crash later on when it is freed by OPENSSL_free().
Even if it wouldn't crash there, it still fails to signal the error
and an empty string may be propagated to the callers.
The check also mirrors the other one in the same file.
Signed-off-by: ndossche <nora.dossche@ugent.be>
PR-URL: https://github.com/nodejs/node/pull/65200
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
A package.json that exists but cannot be read was treated the same as
one that is not there: the read failure returned no config and
resolution continued as if the package had none. Fields such as
"exports" and "type" silently disappear, so a specifier can resolve to
a different file than the package declares, while an unparsable
package.json already throws ERR_INVALID_PACKAGE_CONFIG.
Keep treating ENOENT and ENOTDIR as "no package config here", and
report any other read failure with the underlying error.
Fixes: https://github.com/nodejs/node/issues/65220
Signed-off-by: Paul Bouchon <mail@bitpshr.net>
PR-URL: https://github.com/nodejs/node/pull/65223
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>