nodejs/node

win, cluster: no callback called after write

Open

#19.452 geöffnet am 19. März 2018

Auf GitHub ansehen
 (2 Kommentare) (1 Reaktion) (0 zugewiesene Personen)JavaScript (35.535 Forks)batch import
clusterhelp wantedstalewindows

Repository-Metriken

Stars
 (117.218 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 18T 17h) (219 gemergte PRs in 30 T)

Beschreibung

  • 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