Skip to content

win, cluster: no callback called after write #19452

Open
@bzoz

Description

@bzoz
  • Version: 9.6.0
  • Platform: Windows
  • Subsystem: cluster

On Windows, after calling process.disconnect callbacks for previous process.send calls are not called. Example:

'use strict';
const cluster = require('cluster');

if (cluster.isMaster) {
  cluster.fork().on('message', (msg) => {
    console.log(msg.msg);
  });
} else {
  process.send({msg: 'hello'}, () => {
    console.log('cb!');
  });
  process.disconnect();
}

On Windows this will print:

hello

whereas on Linux it will print

hello
cb!

This was reported in libuv/libuv#1729, but it looks like some issue with cluster module. Callbacks are called on both platforms in the following code, which uses bare IPC pipe:

const cp = require('child_process');

if (process.argv[2] === 'child') {
  process.send({msg: 'hello'}, () => {
    console.log('cb!');
  });
  process.disconnect();
} else {
  const child = cp.spawn(process.argv0, [__filename, 'child'], {
    stdio: ['inherit', 'inherit', 'inherit', 'ipc']
  });
  child.on('message', (msg) => {
    console.log(msg.msg);
  })
}

On Windows this will print:

hello
cb!

and on Linux:

cb!
hello

/cc @nodejs/platform-windows @nodejs/cluster

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.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions