nodejs / nodejs/node

Provide a way to get worker initialization error synchronously

Open
#51,679 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

What is the problem this feature will solve?

I'm using a worker to run asynchronous tasks and block the main thread with Atomics.wait().
If the worker has something like syntax errors, it seems that we can only get it by add a listener to error event, the program just hangs since worker can not wake the main thread.

new (require('worker_threads').Worker)(new URL('data:text/javascript,throw new Error'));
What is the feature you are proposing to solve the problem?

Provide a way to get the worker initialization error synchronously.

What alternatives have you considered?

I tried to pass a timeout to Atomics.wait(), but It's just a random magic number because I don't know how long the worker script takes to init.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the worker_threads Worker initialization and error-event behavior, using the data URL with a syntax error as the reproduction. Check how Atomics.wait() interacts with worker startup, then define and test what synchronous initialization failure should look like without relying on a timeout.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.