Skip to content

chore: merge upstream v5.2.0 - #51

Open
aborovsky wants to merge 23 commits into
developfrom
chore/sync-upstream-5.2.0
Open

aborovsky wants to merge 23 commits into
developfrom
chore/sync-upstream-5.2.0

Conversation

@aborovsky

Copy link
Copy Markdown
Collaborator

What

Merges JCMais/node-libcurl develop (v5.2.0 plus one docs commit) into our develop. The merge base was upstream 5.1.2. Upstream brings 19 commits; two of them (the Node.js 26 end dispatch 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/Easy lifetime: Multi#close() releases the wrapper, Curl#close() cancels transfers on the owning Multi (also with setMulti()), cleanup is deferred when close() runs inside a libcurl callback, HTTP/2 push callbacks restored.
  • READFUNCTION/SEEKFUNCTION hardening, callback error retention, option data lifetimes.
  • Response parsing: parseHeaders splits on the first colon and accepts empty and compact headers.
  • Option dispatch and enum fixes, new libcurl 8.20 options.
  • Bundled Brotli 1.2.1 (CVE fix) on all platforms; build.sh now fails if libcurl does not report brotli/1.2.1.
  • Windows source builds no longer hit MAX_PATH in deeply nested pnpm stores.

Conflict resolution

File Resolution
src/Multi.cc, src/Multi.h Upstream moved the libuv callback scope from OnTimeout/OnSocket into the new SocketAction. Took upstream and moved our OpenSslErrorQueueGuard from OnTimeout/OnSocket into SocketAction, right after the callback scope, so it also covers the deferred curl_multi_cleanup.
.github/actions/setup-libcurl-cache/action.yaml Kept our libc variant in the cache key and appended upstream's build-script hash.
package.json Kept the @brightsec name and the fork version; the release workflow bumps it.

Against upstream/develop, the only remaining source differences in src/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 in Easy.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.json now pulls brotli from a pinned vcpkg git registry on Windows.

Local verification (macOS arm64, Node 24, Homebrew libcurl 8.21)

  • Built from source with pnpm pregyp rebuild; pnpm lint and pnpm build:dist pass.
  • 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 unmodified upstream/develop and on our develop with the same libcurl, so it comes from libcurl 8.21, not from this merge.

JCMais and others added 22 commits June 10, 2026 15:34
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

1 active (outdated) deployment
release — cc183100 Deployed Nov 26, 2026 by aborovsky via release #47
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