Without an async context, napi_make_callback went through the public
node::MakeCallback(), which looks up the Environment from the creation
context of the callback on every call. The napi_env already knows it,
so call into it directly, as the path with an async context does.
node_napi_env__::node_env() also looked it up from the context on every
call: find it once, a napi_env lives as long as its Environment.
Add a benchmark, napi/make_callback_napi.
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/66509
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
stringPercentDecode() UTF-8 encodes its input into a fresh Uint8Array
and then percent-decodes it into a second array of the same size. After
URL parsing, a data: URL body contains '%' only when it has non-ASCII or
control characters or explicit escapes, so plain-text and base64 bodies
were copied byte-for-byte for nothing.
Return the encoded bytes directly when the input contains no '%'. UTF-8
never emits 0x25 inside a multi-byte sequence, so the result is
identical, and each call still returns its own buffer.
When there is a '%', pass its index to percentDecode(), which copies a
long unescaped prefix in bulk and decodes the rest through subarray
views, so the loop still starts at 0 and keeps its bounds checks
eliminated. The string index is used only when every code point encoded
to a single byte, so it is also the byte index.
Signed-off-by: Yaroslav Chuhai <yaroslavchuhai@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67684
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
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>
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>
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>
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>
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>
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>
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>
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>
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>
readCentralDirectory() appends one CentralFileHeader per archive entry
with ArrayPrototypePush, which is listed among primordials with known
performance issues. Assign by the existing loop index instead. The
loop runs once per entry, so its trip count grows with archive size.
The change is limited to this loop. Validation and error behavior are
unchanged.
Assisted-by: Claude Code
Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
PR-URL: https://github.com/nodejs/node/pull/67456
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
The description of response.writeProcessing() was copied from
response.writeContinue() and said that the request body should be
sent, which is what 100 Continue means, not 102 Processing.
Describe what 102 means, document the callback that both methods
have always accepted, and point to the equivalent
response.writeInformation() call.
Signed-off-by: inoway46 <inoueyuya416@gmail.com>
Assisted-by: Claude Code
PR-URL: https://github.com/nodejs/node/pull/67705
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Tim Perry <pimterry@gmail.com>
getpeername(2) on a Unix domain socket returns the path the peer is
bound to, but the pipe handle had no getpeername method, so
socket.remoteAddress was always undefined for pipe connections.
Add getpeername to the pipe handle, backed by uv_pipe_getpeername(), so
that socket.remoteAddress reports the listening path on the connecting
side and the path of a bound client on the accepting side. It remains
undefined for an unbound peer, and on Windows, where a named pipe has a
single name rather than one per end.
Signed-off-by: Guy Bedford <guybedford@gmail.com>
Assisted-by: Claude Fable 5.2
PR-URL: https://github.com/nodejs/node/pull/67402
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: James M Snell <jasnell@gmail.com>