[1.29.x][regression] segfault when require()-ed from a worker thread in Node 22/Linux
Reproduced locally (fedora 41/kernel 6.12.8/node 22.13.0) and on our Linux CI machines (ubuntu-based, I believe).
Steps to reproduce:
mkdir lightning-segfault
cd lightning-segfault
npm init -y
npm i lightningcss
echo "const { Worker } = require('worker_threads'); new Worker(require.resolve('./worker.cjs'));" > entry.cjs
echo "require('lightningcss')" > worker.cjs
node entry.cjs
1.28.x works
1.29.x prints Segmentation fault (core dumped) and crashes the process
Basic steps with GDB say:
Thread 13 "node" received signal SIGSEGV, Segmentation fault.
(gdb) backtrace
#0 0x00007fffce5a0ef0 in ?? ()
#1 0x00007ffff7a79e30 in __nptl_deallocate_tsd () from /lib64/libc.so.6
#2 0x00007ffff7a7cf02 in start_thread () from /lib64/libc.so.6
#3 0x00007ffff7b010cc in __clone3 () from /lib64/libc.so.6
not sure whether the above is useful without additional debug symbols.
Probably related to this Rust bug: https://github.com/rust-lang/rust/issues/91979. The workaround is to load the native module on the main thread in addition to the worker so that it never gets unloaded.
Probably related to this Rust bug: rust-lang/rust#91979. The workaround is to load the native module on the main thread in addition to the worker so that it never gets unloaded.
Appreciate the workaround, even though it won't help our case. We've got code from "repo A" loading other pieces of code from a separate "repo B" without knowing B uses lightningcss in its logic or not.
You may want to also verify that you only have one copy of lightningcss installed (e.g. check your lock file). It's possible that multiple versions could conflict somehow, but not sure.
While multiple versions are indeed a cause of pain for many libs, I'm pretty certain that's not the case here.
See isolated steps to reproduce in the report. I can't see how multiple versions could have happened in that scenario.
Our larger project (where this happened) also had a single version AFAIK.
I believe tailwindcss found a workaround: https://github.com/tailwindlabs/tailwindcss/pull/17276