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

Doesn't catch process.exit() in the worker thread #304

Closed
dko-slapdash opened this issue Nov 28, 2022 · 1 comment · Fixed by #361
Closed

Doesn't catch process.exit() in the worker thread #304

dko-slapdash opened this issue Nov 28, 2022 · 1 comment · Fixed by #361

Comments

@dko-slapdash
Copy link

If a worker thread calls process.exit(), it doesn't seem like Piscina catches that, i.e. it doesn't restart the worker thread or anyhow marks it as "non-existing". I.e. the next job scheduled may be sent to that "zombie" worker and stuck there forever unnoticed.

I found out that this code: https://github.com/piscinajs/piscina/blob/current/src/index.ts#L668 triggers in such a situation, but it doesn't remove the thread from the pool nor does anything else.

Notice that if the worker thread is terminated on an error (e.g. with throw Error("ouch") in its setTimeout() handler, i.e. by producing a fatal uncaughtException), this is handled correctly. The only issue is with a worker exiting "successfully" (and this may actually happen due to some inaccurate written code or something).

Also, worker_threads supports on("exit") event, so there IS a way to catch process.exit() from the worker thread.

@clayjones-at
Copy link
Contributor

@dko-slapdash I'd appreciate it if you could confirm the linked PR fixes the issue for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants