Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when workers exit #83

Open
fmmoret opened this issue Aug 16, 2022 · 5 comments
Open

Segmentation fault when workers exit #83

fmmoret opened this issue Aug 16, 2022 · 5 comments

Comments

@fmmoret
Copy link

fmmoret commented Aug 16, 2022

I get segfaults on node 16 and node 18 when I use these in workers.

I'm on linux gnu x64


Replication steps:

Just run node segfault.js with:

segfault.js

var import_worker_threads = require("worker_threads");

if (import_worker_threads.isMainThread) {
  const worker = new import_worker_threads.Worker("./segfault");
} else {
  var import_snappy = require("snappy");
}

If the parent thread has also imported it, it seems to work fine:

segfault.js with parent import:

var import_worker_threads = require("worker_threads");
var import_snappy = require("snappy");

if (import_worker_threads.isMainThread) {
  const worker = new import_worker_threads.Worker("./segfault");
}
@fmmoret
Copy link
Author

fmmoret commented Aug 16, 2022

opened parent issue too: napi-rs/package-template#308

@Brooooooklyn
Copy link
Owner

It's a known issue upstream: rust-lang/rust#91979

My suggestion is don't use woker_threads with NAPI-RS packages, because the async function exposed in snappy or other NAPI-RS packages could have been possible to take advantage of the multi-cores.

In snappy for example:

Promise.all([
  compress("hello"),
  compress("hello"),
  compress("hello"),
  compress("hello"), 
])

the code below will execute in four threads.

@hanlakewind
Copy link

@Brooooooklyn So you mean that compress() and uncompress() functions are already multi-threaded without worker threads? If so I feel like this information should be put in the README

@Brooooooklyn
Copy link
Owner

So you mean that compress() and uncompress() functions are already multi-threaded without worker threads? If so I feel like this information should be put in the README

@hanlakewind Yes, they are already multi-threaded, I'll update README.

@fmmoret
Copy link
Author

fmmoret commented Aug 25, 2022

Got it. I am just using a pool of worker threads for a job queue and happen to be using snappy for some stuff -- caught me by surprise that my queue would crash if I ever had a job NOT doing snappy compression.

Forcing it to stay loaded by requiring in the parent process works for now

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

No branches or pull requests

3 participants