Repository navigation
Description
Nixpkgs version
- Unstable (26.11)
Describe the bug
When building packages that use worker_threads with sync file I/O (e.g. pnpm 11 installing dependencies), nodejs 24.15.0+ built by nixpkgs spams warnings:
(node:7511) Warning: File descriptor 46 opened in unmanaged mode twice
(node:7511) Warning: File descriptor 46 closed but not opened in unmanaged mode
Under heavy load (e.g. GHA runners), this leads to SIGKILL and build failures.
This is a build-inputs issue, not a nodejs code issue. Upstream node builds (static linking) cannot reproduce this.
Steps to reproduce
- Create
main.cjs:
const { Worker } = require('node:worker_threads');
const worker = new Worker(__dirname + '/worker.cjs');
worker.on('error', (e) => { console.error(e); process.exit(1); });
worker.on('exit', (c) => console.log('exited', c));- Create
worker.cjs:
const { openSync, readSync, closeSync } = require('node:fs');
for (let i = 0; i < 800; i++) {
const fd = openSync('/dev/null', 'r');
const buf = Buffer.alloc(16);
readSync(fd, buf, 0, 16, 0);
closeSync(fd);
}
console.log('worker: 800 sync open/read/close done');- Run:
node --trace-warnings main.cjsOn the nixpkgs aarch64-darwin build of nodejs 24.15.0/24.16.0, this produces ~1599 warnings. On 24.14.1, 24.18.0, nodejs_22, and official nodejs.org builds, it produces 0 warnings.
Expected behaviour
No warnings. Sync file I/O in a worker thread should not trigger fd tracking warnings.
Screenshots
No response
Relevant log output
worker: 800 sync open/read/close done
(node:11967) Warning: File descriptor 14 closed but not opened in unmanaged mode
at Object.<anonymous> (.../worker.cjs:8:3)
at Module._compile (node:internal/modules/cjs/loader:1830:14)
(node:11967) Warning: File descriptor 14 opened in unmanaged mode twice
at openSync (node:fs:561:18)
at Object.<anonymous> (.../worker.cjs:5:14)
at Module._compile (node:internal/modules/cjs/loader:1830:14)
... (1599 warnings total)Additional context
Root cause
Comparing the build inputs of 24.14.1 (clean) and 24.15.0 (broken), the only meaningful difference is the libcxx version:
| 24.14.1 (clean) | 24.15.0 (broken) | |
|---|---|---|
| libcxx | 20.1.0+apple-sdk-26.0 | 21.1.6+apple-sdk-26.4 |
The bug requires all three of:
- V8 13.6.233.17-node.48/.49 (shipped with node 24.15.0/24.16.0)
node_shared_libuv: true(nixpkgs dynamic linking)- libcxx 21.1.x (changed
std::unordered_setABI)
Removing any one of these eliminates the bug. This was verified across 4 builds:
| Build | V8 | libcxx | shared_libuv | warnings |
|---|---|---|---|---|
| nixpkgs 24.14.1 | .44 | 20.1.0 | true | 0 |
| nixpkgs 24.15.0 | .48 | 21.1.6 | true | 1601 |
| nixpkgs 26.4.0 | 14.6 | 21.1.6 | true | 0 |
| official 24.15.0 | .48 | Xcode 16 | false | 0 |
Each clean build removes exactly one condition: 24.14.1 uses libcxx 20 (condition 3), 26.4.0 uses a different V8 (condition 1), and the official build uses static linking (condition 2).
This issue was originally reported in #525627 as a pnpm build failure, but it is a nodejs build issue.
Fix
Pinning the stdenv to llvmPackages_20.libcxxStdenv in pkgs/development/web/nodejs/v24.nix fixes the issue:
buildNodejs = callPackage ./nodejs.nix {
inherit openssl;
python = python3;
+ stdenv = buildPackages.llvmPackages_20.libcxxStdenv;
};I reproduced the Hydra build of 24.15.0 locally using curl https://hydra.nixos.org/build/329352653/reproduce | bash, applied this one-line change, rebuilt, and confirmed 0 warnings. The rebuilt binary is identical except for using libcxx 20.1.x instead of 21.1.x — same V8, same dynamic libuv, same everything else.
System metadata
- system:
"aarch64-darwin" - host os:
Darwin 25.3.0, macOS 26.3.1 - multi-user?:
yes - sandbox:
no - version:
nix-env (Nix) 2.34.7+1 - channels(root):
"nixpkgs" - nixpkgs:
/nix/store/gw7fxaw8z5szcqlzyzcnrshzi60zj664-source
Notify maintainers
Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)
I assert that this issue is relevant for Nixpkgs
- I assert that this is a bug and not a support request.
- I assert that this is not a duplicate of an existing issue.
- I assert that I have read the NixOS Code of Conduct and agree to abide by it.
- I assert that I have read the automation/AI policy and that this issue report complies with it.
Is this issue important to you?
Add a 👍 reaction to issues you find important.
Activity
aduh95 commentedon Jun 28, 2026
It's interesting, I was pretty sure that I tried pinning to
llvmPackages_20without seeing any improvements, but clearly I missed something. Thanks!aduh95 commentedon Jun 28, 2026
Fixed by #536043
mortyccp commentedon Jun 28, 2026
I noticed the OfBorg build logs for #536043 showed failures. After investigating, I suspect the failure was due to the
stdenvoverride being applied unconditionally (including on Linux), which likely caused cross-compilation issues or cache busts.I've pushed a fix to only apply the
libcxxpin for Darwin in my fork: mortyccp@a69eaceI applied this on top of the
stagingbranch and tested the build locally onaarch64-darwin. The build succeeds, and the fd tracking warnings are completely gone (0 warnings, down from ~1600).Question about OfBorg logs:
When looking at the logs in https://logs.ofborg.org/?attempt_id=-ofborg-&key=nixos%2Fnixpkgs.536043, I noticed the header says
system: aarch64-linuxbut the log applies darwin-specific patches (e.g.,darwin-plistbuddy-workaround.patch). Could you help me understand if OfBorg is cross-compiling to Darwin from a Linux builder? This is my first time interacting with OfBorg, and I want to ensure my Darwin-only override works correctly in CI.aduh95 commentedon Jun 28, 2026
Limiting the change is a good idea indeed, doing that in #536336.
I don't know much about OfBorg, but I'm pretty sure it doesn't do any cross-compilation. If a darwin-specific patch has no effect on Linux, it makes sense to apply it so if an update makes it outdated, it can be detected quicker (I haven't checked whether that was the case here)
mortyccp commentedon Jun 30, 2026
Root Cause: V8
std::hashODR violationThe Bug
The
trackUnmanagedFdswarning is caused by an ODR violation in V8'shashing.h, not an LLVM/libc++ ABI bug. V8 injects astd::hash<T>specialization for any typeThashable viav8::base::hash<T>— includingint. This overrides libc++'s identitystd::hash<int>with V8's Thomas Wang scramble, but only in V8 internal translation units (which includehashing.h). Node's own TUs don't includehashing.hand get the identity hash. Both compile the same COMDAT hash-table symbols with different hash function bodies. The linker picks one copy per symbol, causing insert and erase to disagree on the hash of the same value.Node's
trackUnmanagedFdsfeature usesstd::unordered_set<int>to track file descriptors. Due to the ODR violation,insert(fd)stores the entry under the scrambled hash, buterase(fd)looks it up under the identity hash — soerase()can't find the entry and emits the spurious "File descriptor N closed but not opened in unmanaged mode" warning.Timeline
The bug was latent for 7 months, then triggered by an LLVM change, then fixed in V8:
0d102357introducesstd::hash<T>partial specializationstd::hash<int>, which always win over partial specializations in template resolution.std::hashfrom explicit specializations to a SFINAE-based__hash_implstd::hash<int>is now a partial specialization. V8'sstd::hash<T>(also a partial specialization, but more constrained via arequiresclause) wins template resolution in TUs that includehashing.h. The ODR violation becomes active.NetworkInterfaceChangeListenerMojomTraitsTest.OnlineLinks) after rolling the libc++ changestd::hashspecialization overridesstd::hash<int>.65ce14d8removes thestd::hash<T>partial specializationbase::hash<T>explicitly. The libc++ roll (#140407) proceeds forward successfully.Why the bug only manifests with LLVM 21+: Before #140407, libc++ defined
std::hash<int>as an explicit specialization, which always wins over V8's partial specialization — the ODR violation was latent. After #140407, both are partial specializations, and V8's is more constrained (uses arequiresclause), so it wins in V8 TUs — the ODR violation becomes active.nixpkgs build timeline (Darwin aarch64)
All three Node 24.x releases ship V8 13.6.233.17 with the
std::hashoverride. The difference between passing and failing is the LLVM/libc++ version in the nixpkgs stdenv:trackUnmanagedFdstest failsScope
std::hashoverride was introduced in V8 13.x (0d102357) and is present in Node 24's V8 13.6.233 (hashing.h#L364-L369). Node 22 (V8 12.4) and Node 20 do not have this code. Node 25 (V8 14.1) and Node 26 (V8 14.6) already include the upstream fix (65ce14d8) and are not affected.Upstream Fix
Introduced in V8 commit
0d102357, fixed in V8 commit65ce14d8— Chromium bug 424006386.The upstream fix removes the
std::hash<T>specialization and changes V8's internal code to usebase::hash<T>explicitly (3 files:hashing.h,profile-generator.h,canonical-types.h). Node.js hasn't yet picked up this fix in any 24.x release.Recommended Fix
Backport the upstream V8 fix as a patch in
v24.nix(all 3 files). This fixes the root cause on all platforms and removes the need for thellvmPackages_20pin.References
hashing.hoverride: https://github.com/nodejs/node/blob/v24.x/deps/v8/src/base/hashing.h#L364-L369[-]nodejs_24: fd tracking warnings ("opened in unmanaged mode twice") on aarch64-darwin due to libcxx 21 ABI change[/-][+]nodejs_24: fd tracking warnings ("opened in unmanaged mode twice") on aarch64-darwin due to libcxx 21 change[/+]Jack-Works commentedon Jul 9, 2026
I'm using nodejs_26 from unstable channel, which is also affected. Do we need a patch for nodejs_26? By the way the fix for nodejs_24 is still in the staging channel, not in nixpkgs-unstable
aduh95 commentedon Jul 9, 2026
No, nodejs_26 is not affected, see the explainer in the OP for more details. If you're seeing issues, you're either unknowingly using
nodejs_24, or seeing another (likely unrelated) error.FYI there's no such thing as a staging channel, at least not in the official channels.
Unfortunately it will take a while for the fix to make its way to unstable (ironically it should be available on stable before unstable), there's nothing to do but wait (I mean, you can always use an overlay, depending on your use case, that may or may not be worth it).
Jack-Works commentedon Jul 10, 2026
You are correct! I found my
pnpmis installed bycorepack, which usesnodejspackage (24). I need to override it with nodejs_26.Yes, I mean the staging git branch.
aduh95 commentedon Jul 24, 2026
Update: Hydra has built the patched version on both stable and unstable channels
chore(nix,opencode): drop resolved nixpkgs workarounds, add homebrew …
bump flake.lock (fix mac ci)
bump flake.lock (fix mac ci)
bump flake.lock (fix mac ci)
bump flake.lock (fix mac ci)