GeezerVison is showing github.com — cluster.on('message') not return worker · Issue #5764 · nodejs/node
cluster.on('message') not return worker #5764Labels clusterIssues and PRs related to the cluster subsystem.docIssues and PRs related to Node.js documentation. Description
- Version: 4.4.0, 5.9.0
- Platform: Linux test 4.4.4-calculate deps: update openssl to 1.0.1j #1 SMP PREEMPT Wed Mar 9 16:35:58 MSK 2016 x86_64 Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz GenuineIntel GNU/Linux
- Subsystem: cluster, documentation
In documentation:
Event: 'message'#
worker <cluster.Worker>
message <Object>
Emitted when any worker receives a message.
but real use is:
cluster.on('message', msg => { /* worker isn`t known */ })
ActivityFishrock123 commented on Mar 17, 2016 @Hamper Try: cluster.on('message', (msg, worker) => { })? Fishrock123 commented on Mar 17, 2016 It does looks like order of the arguments as told by the docs is incorrect though. Hamper commented on Mar 17, 2016 'use strict'
const cluster = require('cluster')
if (cluster.isMaster) {
cluster.on('message', (msg, wrk) => console.log(`msg=${msg}, wrk=${wrk}`))
cluster.fork()
} else {
cluster.worker.send('test')
process.send('test2')
}
result:
msg=test, wrk=undefined
msg=test2, wrk=undefined
mscdex commented on Mar 17, 2016 The documentation agrees with master, but not 5.x/4.x. MylesBorins commented on Mar 17, 2016 a doc fix PR should be made targeting both v5.x and v4.x-staging
edit: this will need to be 2 pr's mscdex commented on Mar 17, 2016 Looks like the worker argument was added/fixed in 66f4586. jasnell commented on May 1, 2016 Cobraeti commented on May 17, 2016 Hi,
Is it planed to be fixed in LTS version?
I just downloaded the last one (v4.4.4 from 05/05/2016) and it is still behaving as discribed in @Hamper 's first post... Knighton910 commented on May 17, 2016 In the top of your else statement try this process.on('message') Cobraeti commented on May 18, 2016 Hi @lordKnighton ,
I already use process.on('message') as my worker emits that event in a sub-sub-sub-module and I don't want to pass the Cluster object to all intermediate module ^^
The problem is in the other way, when using the process.send() method (worker's syde).
As described by @Hamper , the cluster.on('message') method receives only a message parameter, so when using the following code:
var cluster = require('cluster');
if(cluster.isMaster) {
cluster.on('message', function(worker, message) {
console.log(`Worker ${worker.id} said "${message}"`);
console.log(`Worker ${worker} said "${message}"`);
}
cluster.fork();
}
else {
process.send('Hello World!!!!');
}
The result in console is:
Worker unknow said "unknow"
Worker Hello World!!!! said "unknow"
Cobraeti commented on May 18, 2016 I've just tested the same code within Node.js v6.1.0 and it works like a charm.
It seems that the change has been implemented in that version (don't know for v5.x).
Hopefully, my dependencies can now compile again (that was not the case whith v5.x a few weeks ago), so I would definitely switch to this better one.
I hope my comment will at least help to bring up the issue for those who can't switch version... cjihrig commented on Jun 14, 2016 A fix for v4.x-staging is at #7297. I'm inclined to not fix v5.x, as it is EOL in a couple weeks. cjihrig commented on Jun 15, 2016 added docIssues and PRs related to Node.js documentation. and removed docIssues and PRs related to Node.js documentation. on Dec 1, 2016
MetadataMetadataclusterIssues and PRs related to the cluster subsystem.docIssues and PRs related to Node.js documentation. DevelopmentNo branches or pull requestsIssue actions
|