Skip to content

Prepare for the 5.2.0 release - #54

Merged
aborovsky merged 43 commits into
masterfrom
develop
Nov 27, 2026
Merged

aborovsky merged 43 commits into
masterfrom
develop

Conversation

@aborovsky

Copy link
Copy Markdown
Collaborator

Brings master up to develop at 5.2.0-2 (e84f9ef) so publish.yml can release 5.2.0 from master. master has no commits that develop lacks, so this merge only adds develop's 43 commits.

Since 5.1.6 this adds:

5.2.0-2 was published from the same commit and passed bright-cli's unit tests and e2e.

JCMais and others added 30 commits June 10, 2026 15:34
The Linux and Windows prebuilds resolve libcurl's OpenSSL calls to the
OpenSSL that Node exports, so both share the per-thread error queue.
CURLOPT_SSLENGINE first tries to load the provider by name from the
modules directory, which is the null device in Node's build, and that
failure stays queued even when the provider then loads from OPENSSL_CONF.
Node's next SSL_read() on any TLS socket saw the stale error through
SSL_get_error() and destroyed the socket.

Clear the queue after Easy and Multi calls into libcurl, after
curl_multi_socket_action() and before the onMessage callback.
Easy.close() now clears the error queue as well, so a missing setOpt
guard went unnoticed when the second request ran after it. Send it while
the handle is still open. Node detaches a kept-alive socket from the
response before `end`, which made the socket comparison pass with two
nulls; take the socket from the request's `socket` event and also assert
`reusedSocket`.
fix: clear the openssl error queue when control leaves libcurl
Multi::OnSocket and Multi::OnTimeout enter JS from a libuv callback, that
is, from outside any JS context. Multi::CallOnMessageCallback settles the
promise perform() returns from there, and Node.js only performs a
microtask checkpoint when a callback scope is closed. Only a HandleScope
was being opened, so the continuation that emits `end` was not scheduled
until something else drained the microtask queue - and for a caller
awaiting one request at a time, that is the next tick of libcurl's own
multi timer.

On Node.js 26 / Linux this made every serialized request take ~1000ms
even though the transfer itself completed in under 3ms: headers and body
arrived at ~2ms and CURLINFO_TOTAL_TIME_T reported 0.5-2.8ms. Issuing
requests concurrently masked it, because the other in-flight transfers
kept waking the loop. Node.js 22, 24 and 25 were unaffected, as was
macOS.

Open a Napi::CallbackScope in both libuv callbacks, backed by a single
long-lived AsyncContext per Multi so that no napi_async_init happens per
socket event. Easy::CallSocketEvent, the only other libuv -> JS entry
point, already used MakeCallback with an async context and needed no
change.

Serialized throughput on node:26-alpine goes from 1.3 to 3046 req/s
(p50 995.7ms -> 0.29ms). Node.js 24 is unchanged within noise.
The default Multi drains completions from Multi::NotifyCallback when built
against libcurl >= 8.17, and directly from OnSocket / OnTimeout otherwise.
Both sit inside the callback scopes the previous commit added, but only the
notification-enabled path was exercised here, leaving the polling fallback
covered incidentally by whichever CI leg happens to build against an older
libcurl.

Parameterize the helper with an optional Multi and add a case pinned to
`new Multi({ shouldUseNotificationsApi: false })`, closing it afterwards.
Both cases fail on the unfixed addon (8.4s and 7.0s for 11 requests) and
pass with it.
Calling multi.close() from inside onMessage, as examples/04-multi.js does,
runs Dispose() while the callback scope opened by OnSocket / OnTimeout is
still open. Dispose() reset the only reference to the async context, so
napi_async_destroy freed it under the open scope. Since Node.js 25,
napi_open_callback_scope pushes a pointer to the context's resource onto
the async resource stack, and anything that read it before the scope
closed (executionAsyncResource(), AsyncLocalStorage) read freed memory:
it returned undefined, or crashed under Guard Malloc.

Hold the context in a shared_ptr and take a local copy for the lifetime
of each scope, so it is destroyed only after the scope closes.

The regression test runs on the polling path. With the notifications API,
onMessage runs inside libcurl's notify callback, and curl_multi_cleanup
fails there with CURLM_RECURSIVE_API_CALL.
curl_multi_cleanup returns CURLM_RECURSIVE_API_CALL while
curl_multi_socket_action is on the stack, which tripped the assert in
Dispose. That is the case for close() from onMessage on libcurl >= 8.17
(notifications API, the default, as in examples/04-multi.js) and for
close() from an Easy callback on any version. Dispose now marks the
cleanup as pending, and it runs once curl_multi_socket_action returns.

OnTimeout and OnSocket now share a single SocketAction helper that owns
the callback scope, so the async context lifetime rule from JCMais#455 lives
in one place. OnSocket stops its poll handle if it fires after close()
instead of returning while the socket keeps waking the loop, and
HandleTimeout ignores timer requests after close().

Also declare Multi::Finalize(Napi::Env) so node-addon-api runs Dispose
through node_api_post_finalizer instead of inside the GC, where
napi_async_destroy is a fatal error. Not reachable today, since an open
Multi keeps a self reference, but cheap to rule out.

The multi spec now covers both dispatch paths, checks that the async
resource is the same object before and after close(), and adds a close
from WRITEFUNCTION case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… fix

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Windows, depending on node-addon-api's node_addon_api_except target
makes gyp's msvs generator emit a .vcxproj for it next to node-addon-api's
real location. In a pnpm store that is a sibling of node-libcurl's own
folder, so MSBuild writes that project's intermediate files under
.pnpm\node-libcurl@...\node-addon-api@8.5.0\node_modules\node-addon-api\.
In the nested consumer used by windows-consumer-install the
.lastbuildstate path is ~271 chars, and MSBuild 18 (VS 2026, now
windows-latest) fails with PathTooLongException in WriteLinesToFile.

The target is header-only, so on Windows its settings (NAPI_CPP_EXCEPTIONS,
_HAS_EXCEPTIONS=1, /EHsc, /analyze) are now set directly in binding.gyp,
and the extra project is no longer generated. Other platforms keep the
dependency unchanged; it also supplies MACOSX_DEPLOYMENT_TARGET on macOS,
and the generated macOS makefile is byte-for-byte identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
node-libcurl Bot and others added 13 commits November 26, 2026 02:11
Bring in JCMais/node-libcurl 5.2.0 (Multi/Easy lifetime and transfer
ownership fixes, HTTP/2 push, response parsing, option dispatch, Brotli
1.2.1, Windows MAX_PATH build fix).

Conflict resolution:
- src/Multi.cc, src/Multi.h: take upstream, which moved the libuv callback
  scope from OnTimeout/OnSocket into SocketAction. The OpenSSL error queue
  guard that lived in OnTimeout/OnSocket now sits in SocketAction right after
  the callback scope, so it also covers the deferred curl_multi_cleanup.
- setup-libcurl-cache: keep the libc variant in the cache key and add
  upstream's build-script hash.
- package.json: keep the @BrightSec name and the fork version.
Since VS 18.11 on windows-latest, electron-source-install fails with
PathTooLongException in MSBuild's CL task. The scoped package name adds
@BrightSec twice and makes pnpm hash the .pnpm entry, so the package root
was 178 chars against 150 in upstream, where the same job passes on the
same image. Dropping the 'nested-' * 4 suffix removes exactly those 28
chars.
ci: shorten the Windows consumer install path
The preinstall hook ran scripts/vcpkg-setup.js unconditionally on Windows,
so every npm install built curl and nine dependencies from source (20-30
minutes, needs git and Visual Studio) before node-pre-gyp downloaded the
prebuilt binary that made that build unnecessary.

scripts/install.js replaces the preinstall and install hooks. On Windows it
tries the prebuilt download first and runs vcpkg plus the fallback build only
when the download fails. Explicit source builds (npm_config_build_from_source)
and git checkouts still set up vcpkg first, so CI builds and local
`pnpm pregyp rebuild` keep working. Other platforms are unchanged.

A new windows-consumer-install job installs the packed tarball with npm and
fails if vcpkg ran or the install takes longer than 15 minutes.
A failed extraction can leave a partial lib/binding/node_libcurl.node.
A second `node-pre-gyp install` treats any file at that path as installed
and skips the build, so npm could finish with a corrupt addon. Use
--build-from-source, whose rebuild deletes module_path before compiling.
…built

fix(windows): run vcpkg only when the prebuilt binary is unavailable
@aborovsky
aborovsky merged commit a90bbad into master Nov 27, 2026
153 of 156 checks passed
@aborovsky aborovsky self-assigned this Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants