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

Bug: wrong return value for node worker_thread.terminate() #23801

Closed
marvinhagemeister opened this issue May 14, 2024 · 0 comments · Fixed by #23803
Closed

Bug: wrong return value for node worker_thread.terminate() #23801

marvinhagemeister opened this issue May 14, 2024 · 0 comments · Fixed by #23803
Labels
bug Something isn't working node compat

Comments

@marvinhagemeister
Copy link
Contributor

The .terminate() method is supposed to return a Promise, see https://nodejs.org/api/worker_threads.html#workerterminate , but we return undefined instead. This is one of the reason the tinypool library is unable to terminate workers.

Steps to reproduce

  1. Create file worker.js with some content like console.log("worker")
  2. Create file main.ts with these contents:
import { Worker } from "node:worker_threads";
import * as path from "node:path";

const worker = new Worker(path.join(import.meta.dirname!, "worker.js"));
worker.terminate().then(() => {
  console.log("terminated");
});
  1. Run DENO_FUTURE=1 deno run -A main.ts

Error

$ DENO_FUTURE=1 deno run -A main.ts
worker
error: Uncaught (in promise) TypeError: worker.terminate(...).then is not a function
worker.terminate().then(() => {
                   ^
    at file:///Users/marvinh/dev/test/deno-node-worker/main.ts:5:20

Version: Deno 1.43.3

@marvinhagemeister marvinhagemeister added bug Something isn't working node compat labels May 14, 2024
marvinhagemeister added a commit that referenced this issue May 15, 2024
<!--
Before submitting a PR, please read
https://docs.deno.com/runtime/manual/references/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
7. Open as a draft PR if your work is still in progress. The CI won't
run
   all steps, but you can add '[ci]' to a commit message to force it to.
8. If you would like to run the benchmarks on the CI, add the 'ci-bench'
label.
-->

Fixes #23801

---------

Signed-off-by: Marvin Hagemeister <marvinhagemeister50@gmail.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
bartlomieju added a commit that referenced this issue May 16, 2024
<!--
Before submitting a PR, please read
https://docs.deno.com/runtime/manual/references/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
7. Open as a draft PR if your work is still in progress. The CI won't
run
   all steps, but you can add '[ci]' to a commit message to force it to.
8. If you would like to run the benchmarks on the CI, add the 'ci-bench'
label.
-->

Fixes #23801

---------

Signed-off-by: Marvin Hagemeister <marvinhagemeister50@gmail.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant