fix(test): probe the native binding out of process - #2232
Merged
Conversation
The natives globalSetup I added in #2224 turned every Linux `suites` run red, including on main. Each run passes all ~5960 tests on both retry attempts and then dies with `exit code 139` -- SIGSEGV during exit. main was green at ad21551 and red at the very next run, 6546900, which is #2224. The only other commit in that range is #2225, which changes timeout numbers, a contract test and docs, and cannot segfault. The sole new executable code is test/global-setup-natives.ts. Cause: `bindingLoads()` called `createRequire(...)(NATIVE_ENTRY)`, and globalSetup runs in vitest's ORCHESTRATOR -- the process owning the worker pool. That dlopened the NAPI addon into a process that otherwise never touches it; workers load it on demand in their own processes. The addon carries #2205's Rust control plane and its Tokio runtime, so on glibc Linux its destructors run at exit alongside pool teardown and the process dies after the suite has already succeeded. The probe now runs in a child: `node -e "require(<entry>)"`, exit 0 means loadable. That keeps every property the check was chosen for -- a real load attempt rather than a filename scan, so it cannot drift from napi-rs's ~700 lines of platform-arch-libc resolution, and a foreign-platform binding still triggers a rebuild -- while the orchestrator never loads the addon. It costs one short spawn on a path that already spawns a Rust build when the binding is missing. Verified locally on all three paths: warm (2.9s, silent), foreign binding present (reports "present but not loadable here" and rebuilds), and full unit suite 625 files / 5957 tests, exit 0. I could not reproduce the segfault locally because I only ever ran this suite on macOS, which is also why #2224 shipped with it. The proof is this PR's own Linux `suites` job. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
The natives
globalSetupI added in #2224 turned every Linuxsuitesrun red — including onmain, and therefore on every PR branched from it.Each run passes all ~5960 tests on both retry attempts and then dies with
exit code 139(SIGSEGV) during exit.Attribution
mainrunsuites(linux-x64)ad215516365469006c70d862d24ad2155163..65469006ccontains exactly two commits, both mine:e43c64932ci: size the suites caps for the retries that job actually owns #2225 — timeout numbers, a contract test, docs. Cannot segfault.65469006ctest: build the native binding when it is missing, warn when it is stale #2224 — addstest/global-setup-natives.ts, the only new executable code in the range.Cause
globalSetupruns in vitest's orchestrator — the process that owns the worker pool. Thatrequiredlopens the NAPI addon into a process which otherwise never touches it; workers load it on demand, in their own processes.The addon carries #2205's Rust control plane and its Tokio runtime. On glibc Linux its destructors run at exit alongside pool teardown, and the process dies after the suite has already succeeded. Consistent with every observation: exit 139 after
5968 passed, on both attempts, Linux only.Fix
Probe in a child process. Exit 0 means loadable; the orchestrator never loads the addon.
This keeps every property the load-check was chosen for in review:
.nodewould skip the build. Still true here.Cost is one short spawn, on a path that already spawns a Rust build when the binding is missing.
Verification
Three paths, locally:
npm run checkclean.What I got wrong
I ran that suite locally many times while writing #2224 — always on macOS, which does not reproduce this. I chose the
require()probe because the filename scan was correctly rejected in review, and never asked which process would be doing the loading.I have not reproduced the segfault locally. The attribution rests on the exact commit boundary, the inert alternative, and a mechanism consistent with the platform split. The proof is this PR's own Linux
suitesjob.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Greptile Summary
This change moves the native addon load check out of Vitest’s orchestrator and into a short-lived Node process, avoiding direct native-module loading in the process that manages test workers. Runtime checks confirmed that the real binding loads successfully, Vitest completes with the updated setup, and an intentionally non-loadable binding enters the rebuild-and-fail path rather than being accepted.
Confidence Score: 5/5
Safe to merge based on the focused native-binding and Vitest setup checks.
The exercised success path completed normally with the real native binding, and the exercised failure path correctly rejected a non-loadable binding and invoked the rebuild behavior.
Files Needing Attention: No files need additional attention; the reviewed change is limited to test/global-setup-natives.ts.
What T-Rex did
Reviews (1): Last reviewed commit: "fix(test): probe the native binding out ..." | Re-trigger Greptile