workerpool icon indicating copy to clipboard operation
workerpool copied to clipboard

`worker.exit` should set `process.exitCode` instead of calling `process.exit` to allow cleanup

Open cha0s opened this issue 1 year ago • 7 comments

cha0s avatar Feb 07 '24 15:02 cha0s

Ahh, I was not aware of that. Who knows, this may explain some of the issues regarding exiting that we've seen in the past.

For context:

  • https://stackoverflow.com/questions/5266152/how-to-exit-in-node-js
  • https://nodejs.org/api/process.html#processexitcode

josdejong avatar Feb 09 '24 16:02 josdejong

Anyone able to work this out in a PR?

josdejong avatar Feb 09 '24 16:02 josdejong

Just as a little context, I encountered this library when working with mocha --parallel which uses workerpool to handle its workers.

This is what I came up with for the mean time to reliably(?) run cleanup tasks from within a worker:

  process.prependListener('message', async (message) => {
    if ('__workerpool-terminate__' === message) {
      // ...
    }
  });

I might be able to get a PR on this soonish, but I would definitely want to familiarize myself a little more with the code than the quick spelunk that led me to bring this issue to your attention.

Thanks for the response!

cha0s avatar Feb 10 '24 00:02 cha0s

Thanks for the clarification Ruben! Help working this out in a solution would be very welcome.

josdejong avatar Feb 12 '24 17:02 josdejong