Skip to content

fix: #598 clean up a worker that already exited before terminate - #601

Open
akashchamp wants to merge 1 commit into
josdejong:masterfrom
akashchamp:fix-exited-worker-cleanup
Open

akashchamp wants to merge 1 commit into
josdejong:masterfrom
akashchamp:fix-exited-worker-cleanup

Conversation

@akashchamp

Copy link
Copy Markdown

Fixes #598.

When an abort listener rejects, the worker exits on its own. The cleanup timeout then calls terminate(), which waits for an exit event that was already emitted, so the handler stays cleaning forever: the worker counts as busy, queued tasks never run and pool.terminate() hangs.

The handler now records when its worker has exited, and terminate() cleans up right away in that case. This uses the handler's own exit listener rather than exitCode, so it also works for worker_threads, which hang the same way.

Added a test for both process and thread workers whose abort listener rejects. Both time out on master and pass with the fix. npm test passes on Node 22 and 24 (172 passing). The reproduction from the issue now prints busyWorkers: 0, then pong, and pool.terminate() resolves, for both worker types.

…nate

When an abort listener rejects, the worker exits by itself. The pool then
called terminate() and waited for an exit event that had already been
emitted, so the worker stayed busy forever and pool.terminate() hung.

Remember when the worker has exited and clean it up right away in
terminate(). This covers both process and thread workers.
@joshLong145

Copy link
Copy Markdown
Contributor

Thanks @akashchamp your implementation seems to model my comment regarding the exit event.

I cannot approve but I agree with the implementation.

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

Successfully merging this pull request may close these issues.

Pool keeps a process worker busy forever after it exits itself from a rejected abort listener

2 participants