Skip to content

Calling disconnect causes processes spawned by cluster module to exit too early #27679

Open
@bimbiltu

Description

@bimbiltu
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clusterIssues and PRs related to the cluster subsystem.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions