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: worker_threads missing MessagePort conversion in deeply nested object #23854

Closed
marvinhagemeister opened this issue May 16, 2024 · 0 comments · Fixed by #23871
Closed

Bug: worker_threads missing MessagePort conversion in deeply nested object #23854

marvinhagemeister opened this issue May 16, 2024 · 0 comments · Fixed by #23871
Labels
bug Something isn't working node API polyfill Related to various "node:*" modules APIs node compat

Comments

@marvinhagemeister
Copy link
Contributor

Passing a MesssagePort instance via postMessage inside a deeply nested object is not converted to a node MessagePort.

Steps to reproduce

  1. Create a file worker.mjs with these contents:
import process from "node:process";
import { parentPort } from "node:worker_threads";

parentPort.on("message", (ev) => {
  console.assert(
    typeof ev.foo.bar.addListener === "function",
    "MessagePort doesn't have 'addListener' method"
  );
  process.exit(0);
});
  1. Create a file main.mjs with these contents:
import { Worker, MessageChannel } from "node:worker_threads";

const w = new Worker("./worker.mjs");

const port = new MessageChannel().port1;
w.postMessage({ foo: { bar: port } }, [port]);
  1. Run deno run -A main.mjs

Version: Deno 1.43.3

@marvinhagemeister marvinhagemeister added bug Something isn't working node compat labels May 16, 2024
@bartlomieju bartlomieju added the node API polyfill Related to various "node:*" modules APIs label May 16, 2024
marvinhagemeister added a commit that referenced this issue May 20, 2024
Our `MessagePort` to Node's `MessagePort` conversion logic was missing
the case where a `MessagePort` is sent _inside_ the message. This broke
`tinypool` which is used by `vitest` as it relies on some node specific
methods on `MessagePort`.

Fixes #23854 , Fixes
#23871
bartlomieju pushed a commit that referenced this issue May 21, 2024
Our `MessagePort` to Node's `MessagePort` conversion logic was missing
the case where a `MessagePort` is sent _inside_ the message. This broke
`tinypool` which is used by `vitest` as it relies on some node specific
methods on `MessagePort`.

Fixes #23854 , Fixes
#23871
bartlomieju pushed a commit that referenced this issue May 21, 2024
Our `MessagePort` to Node's `MessagePort` conversion logic was missing
the case where a `MessagePort` is sent _inside_ the message. This broke
`tinypool` which is used by `vitest` as it relies on some node specific
methods on `MessagePort`.

Fixes #23854 , Fixes
#23871
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 API polyfill Related to various "node:*" modules APIs node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants