nodejs/node
Ver no GitHubCalling disconnect causes processes spawned by cluster module to exit too early
Open
#27.679 aberto em 13 de mai. de 2019
clusterhelp wantedstale
Métricas do repositório
- Stars
- (117.218 stars)
- Métricas de merge de PR
- (Mesclagem média 18d 17h) (219 fundiu PRs em 30d)
Description
- Version: 12.2.0 but could also reproduce on 10.15.3
- Platform: Darwin 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64
- Subsystem:
Consider the following script:
const cluster = require('cluster');
const childProcess = require('child_process');
const useCluster = false;
const isMaster = useCluster ? cluster.isMaster : !process.argv.includes('worker');
if (isMaster) {
if (useCluster) {
cluster.fork(__filename);
} else {
childProcess.fork(__filename, ['worker']);
}
} else {
setTimeout(() => console.log('hi from worker'), 1000);
process.disconnect();
}
When useCluster is true node exits immediately and nothing is printed to the console. When useCluster is false you see "hi from worker" logged after 1s and then node will exit which is the expected behavior. The documentation makes it sound like calling process.disconnect should only close the IPC channel between the master and worker process and should not cause either to exit early if there is still work to do.