Repository navigation
Conversation
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>
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.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Merges
JCMais/node-libcurldevelop(v5.2.0 plus one docs commit) into ourdevelop. The merge base was upstream 5.1.2. Upstream brings 19 commits; two of them (the Node.js 26enddispatch fix and its test) were already in the fork as identical patches.Main upstream changes (see the 5.2.0 section of
CHANGELOG.md):Multi#close()releases the wrapper,Curl#close()cancels transfers on the owning Multi (also withsetMulti()), cleanup is deferred whenclose()runs inside a libcurl callback, HTTP/2 push callbacks restored.READFUNCTION/SEEKFUNCTIONhardening, callback error retention, option data lifetimes.parseHeaderssplits on the first colon and accepts empty and compact headers.build.shnow fails if libcurl does not reportbrotli/1.2.1.Conflict resolution
src/Multi.cc,src/Multi.hOnTimeout/OnSocketinto the newSocketAction. Took upstream and moved ourOpenSslErrorQueueGuardfromOnTimeout/OnSocketintoSocketAction, right after the callback scope, so it also covers the deferredcurl_multi_cleanup..github/actions/setup-libcurl-cache/action.yamlpackage.json@brightsecname and the fork version; the release workflow bumps it.Against
upstream/develop, the only remaining source differences insrc/Multi.*are our OpenSSL error queue guards. The other fork-only changes (CI, Alpine/Rocky/macOS/Windows build fixes, GSSAPI, vcpkg mirror, the OpenSSL error queue fix inEasy.cc) carried over unchanged.What to watch in CI
The Brotli change is the main risk for our extra build variants (Alpine arm64 musl in docker, Rocky Linux 8, macOS fat binary): each must link Brotli 1.2.1, and
vcpkg-configuration.jsonnow pulls brotli from a pinned vcpkg git registry on Windows.Local verification (macOS arm64, Node 24, Homebrew libcurl 8.21)
pnpm pregyp rebuild;pnpm lintandpnpm build:distpass.pnpm test: 221 passed, 2 skipped, 1 failed. The failure (setOpt() > BLOB > should be able to set blob value back to null) also fails on unmodifiedupstream/developand on ourdevelopwith the same libcurl, so it comes from libcurl 8.21, not from this merge.