You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a problem:
The Worker doesn't react on "message" event from the Primary with: type: "module" enabled in package.json
But the Primary is react on "message" event from the worker
Without type: "module" both works.
win10 x64 (node v14.17.5 and v16.7.0)
Guys, any fixes? Thanks.
Example:
importclusterfrom'cluster';if(cluster.isMaster){constworker=cluster.fork();worker.on('message',message=>{// will log the messageconsole.log(message);});worker.send('From Master');}else{process.on('message',message=>{// will not log the messageconsole.log(message);});process.send('From Worker');}
tl;dr of the other issues, there's a minor race condition (read: bug) because modules are now loaded asynchronously and when starting a module messages are missed as you don't register in time to get them. The safest way to start without a race condition is to get a ping from the child and then you know you're safe. e.g. POC:
Yes, i saw #37782 after.
"modules are now loaded asynchronously" - With babel or no ESM it works correctly without any timeouts.
Anyway thank you, i did it and it worked.
Yes, i saw #37782 after.
"modules are now loaded asynchronously" - With babel or no ESM it works correctly without any timeouts.
Just to clarify - when I said modules what I meant was that ESM modules (as in type: module or .mjs) are loaded asynchronously (e.g. for top-level await etc), while using CommonJS is still synchronous - not that all code is now loaded asynchronously.
Activity
PurnashisHazra commentedon Aug 23, 2021
Could you create a repo which replicates this problem? Can I take this issue up?
relloccate commentedon Aug 23, 2021
The example above, just a minimal and illustrative example. Pretty simple to test on your PC. Sorry, I did not understand why you need a repo.
PurnashisHazra commentedon Aug 23, 2021
Just with some tests and all for easy debugging . Nevermind, I'll take up this issue
Linkgoron commentedon Aug 27, 2021
This is probably a duplicate of #37782 and #39140
e.g. this works:
tl;dr of the other issues, there's a minor race condition (read: bug) because modules are now loaded asynchronously and when starting a module messages are missed as you don't register in time to get them. The safest way to start without a race condition is to get a ping from the child and then you know you're safe. e.g. POC:
relloccate commentedon Aug 27, 2021
Yes, i saw #37782 after.
"modules are now loaded asynchronously" - With babel or no ESM it works correctly without any timeouts.
Anyway thank you, i did it and it worked.
My Solution:
relloccate commentedon Aug 27, 2021
Dupe of #37782
Linkgoron commentedon Aug 27, 2021
Just to clarify - when I said modules what I meant was that ESM modules (as in
type: moduleor.mjs) are loaded asynchronously (e.g. for top-level await etc), while using CommonJS is still synchronous - not that all code is now loaded asynchronously.