nodejs/node

win, cluster: no callback called after write

Open

#19,452 opened on Mar 19, 2018

View on GitHub
 (1 comment) (1 reaction) (0 assignees)JavaScript (117,218 stars) (35,535 forks)batch import
clusterhelp wantedwindows

Description

  • 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 https://github.com/libuv/libuv/issues/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

Contributor guide

win, cluster: no callback called after write · nodejs/node#19452 | Good First Issue