Skip to content

build: fail loudly when the openssl error queue fix would compile out - #50

Closed
aborovsky wants to merge 2 commits into
developfrom
fix/require-openssl-err-header
Closed

aborovsky wants to merge 2 commits into
developfrom
fix/require-openssl-err-header

Conversation

@aborovsky

Copy link
Copy Markdown
Collaborator

Follow-up to #48, from this review remark: #if __has_include(<openssl/err.h>) quietly compiles the fix out if the header is ever missing.

Where the header is missing, and whether that matters

Build <openssl/err.h> Shares its OpenSSL error queue with libcurl
Node.js, official (bundled OpenSSL), Linux/macOS yes, include/node/openssl/ Linux: yes (the bug). macOS prebuilds: no, own static OpenSSL
Windows, Node.js and Electron yes, vcpkg Node.js: yes
Electron, Linux/macOS no, the 38.6/39.1 headers contain no OpenSSL at all no, Electron (BoringSSL) exports no OpenSSL symbols. nm -D finds none of ERR_clear_error/ERR_get_error/SSL_read/SSL_get_error in electron, but all 4 in node
Node.js built with --shared-openssl (distros) from the system's OpenSSL dev package depends on how libcurl links

So today the header is missing only where the bug can't happen, and there the no-op is correct. Where the bug can happen, the header always ships. A future change to the include path would still drop the fix silently, though, and only the regression test would show it.

Change

  • binding.gyp defines NODE_LIBCURL_REQUIRE_OPENSSL_ERR when node-gyp's config.gypi describes a runtime that exports its bundled OpenSSL: node_use_openssl=="true", node_shared_openssl=="false", and not built_with_electron.
  • src/OpenSslErrorQueue.h turns a missing <openssl/err.h> into an #error there.
  • Everywhere else (Electron, shared OpenSSL) the header stays optional, as before.
  • Opt-out: npm_config_node_libcurl_openssl_err=optional.
  • I don't use an unconditional #include, because it would break every Linux/macOS Electron build. I don't use #pragma message either, because it would print on every Electron build and still not stop anything.

Checked

  • Linux, node:24-trixie (Node 24, bundled OpenSSL): pregyp configure adds the define. With optional it doesn't.
  • Preprocessor: the header compiles with Node's headers. With the define and no OpenSSL include path it stops with the #error.
  • macOS: the Homebrew Node has node_shared_openssl: true, and Electron 39.1.1 has built_with_electron: 1. Neither gets the define.
  • Full build matrix: CI on this PR, Electron jobs included.

The fix includes <openssl/err.h> only if it exists, so a broken include
path would silently drop it. Define NODE_LIBCURL_REQUIRE_OPENSSL_ERR when
node-gyp's config.gypi says the runtime exports its bundled OpenSSL
(node_use_openssl, not node_shared_openssl, not Electron), and turn the
missing header into an #error there. Electron ships BoringSSL without
OpenSSL headers or exports, and a shared system OpenSSL comes with its
own headers, so both keep the header optional.
npm_config_node_libcurl_openssl_err=optional opts out.
@aborovsky aborovsky self-assigned this Nov 13, 2026
@aborovsky
aborovsky requested a review from alonchin November 13, 2026 10:03
Comment thread binding.gyp Resolved
@aborovsky aborovsky closed this Nov 16, 2026
@aborovsky
aborovsky deleted the fix/require-openssl-err-header branch November 26, 2026 12:48
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