nodejs/node

win, cluster: no callback called after write

Open

#19.452 aberto em 19 de mar. de 2018

Ver no GitHub
 (2 comments) (1 reaction) (0 assignees)JavaScript (35.535 forks)batch import
clusterhelp wantedstalewindows

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: 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

Guia do colaborador