cluster.worker.on('message', (msg) => ...) fails to register a callback if ESM file extensions is used
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
Version
v20.3.1
Platform
All supported platform
Subsystem
No response
What steps will reproduce the bug?
After a migration of code to ESM by using .mjs file extensions, the poolifier project has encountered issues at running internal benchmarks code.
Test case:
- main.mjs:
import cluster from 'cluster'
cluster.setupPrimary({ exec: './worker.mjs' })
const worker = cluster.fork()
worker.on('message', message => {
console.info('message received from worker:', message)
})
worker.on('online', () => {
console.info('worker is online')
})
worker.on('error', (error) => {
console.info('worker error', error)
})
worker.on('disconnect', () => {
console.info('worker disconnected')
})
worker.on('exit', () => {
console.info('worker exited')
})
worker.send('hello')
- worker.mjs:
import cluster from 'cluster'
cluster.worker.on('message', message => {
console.info('echo message received from main:', message)
cluster.worker.send(message)
})
node main.mjs is frozen.
How often does it reproduce? Is there a required condition?
100% reproducible
What is the expected behavior? Why is that the expected behavior?
No response
What do you see instead?
Callback is never called if a message is sent from the primary.
Additional information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided main.mjs and worker.mjs reproduction with Node v20.3.1, then inspect the cluster worker message-listener path involved by cluster.worker.on('message'). Done means the callback receives the message sent by worker.send('hello') when the worker uses the .mjs extension, with regression coverage for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100