Skip to content

Need to call .unref() on a worker up to 5 times to actually unref it #31871

@lgarron

Description

@lgarron

Deno 2.6.5
macOS 26.2

Repro:

git clone https://github.com/lgarron/comlink && cd comlink
git checkout deno-unref-repro
npm install

npm run build

# This should return, but it hangs.
npx -- deno run --allow-read -- ./tests/portability/refCount-false.mjs

Uncomment and edit the amount of .unref() calls in tests/portability/refCount-false.mjs to observe that 4 total calls (including the initial) are not enough, but 5 are.

This contradicts the documentation:

https://nodejs.org/api/worker_threads.html#workerunref

Calling unref() on a worker allows the thread to exit if this is the only active handle in the event system. If the worker is already unref()ed calling unref() again has no effect.

This also reproduces using the default image for Codespaces (4 are not enough, but 5 are).

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions