Skip to content

Cluster IPC ERR_IPC_DISCONNECTED EPIPE #32106

Closed
@pool683

Description

@pool683

This is not production code.

'use strict';

const cluster = require('cluster');
const os = require('os');

if (cluster.isMaster) {
  const workers = [];
  const numCPUs = 4; //os.cpus().length;
  var wait_online = numCPUs;
  for (var i = 0; i < numCPUs; i++) {
    const worker = cluster.fork();
    workers[i] = worker;
    worker.on('online', function() {
      if (--wait_online == 0) {
        for (const worker of workers) {
          if (worker.isConnected()) {
            worker.send('die');
          }
        }
      }
    });
    worker.on('error', function(err) {
      console.log(err);
    });
    worker.on('disconnect', function(code, signal) {
      for (const worker of workers) {
        if (worker.isConnected()) {
          worker.send('die');
        }
      }
    });
  }
} else {
  process.on('uncaughtException', (err, origin) => {
    console.log(err);
  });
  process.on('message', function (msg) {
    if (msg == 'die') {
      if (cluster.worker.isConnected()) {
        cluster.worker.disconnect();
      }
    }
  });
}

Randomly generates errors:

Error: write EPIPE
    at ChildProcess.target._send (internal/child_process.js:806:20)
    at ChildProcess.target.send (internal/child_process.js:676:19)
    at sendHelper (internal/cluster/utils.js:22:15)
    at send (internal/cluster/master.js:351:10)
    at exitedAfterDisconnect (internal/cluster/master.js:263:3)
    at Worker.onmessage (internal/cluster/master.js:250:5)
    at ChildProcess.onInternalMessage (internal/cluster/utils.js:43:8)
    at ChildProcess.emit (events.js:228:7)
    at emit (internal/child_process.js:876:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  errno: 'EPIPE',
  code: 'EPIPE',
  syscall: 'write'
}
Error: write EPIPE
    at ChildProcess.target._send (internal/child_process.js:806:20)
    at ChildProcess.target.send (internal/child_process.js:676:19)
    at Worker.send (internal/cluster/worker.js:47:28)
    at Worker.<anonymous> (/run/media/user/Disk/test/worker.js:28:18)
    at Worker.emit (events.js:223:5)
    at ChildProcess.<anonymous> (internal/cluster/master.js:209:12)
    at Object.onceWrapper (events.js:312:28)
    at ChildProcess.emit (events.js:223:5)
    at finish (internal/child_process.js:861:14)
    at processTicksAndRejections (internal/process/task_queues.js:76:11) {
  errno: 'EPIPE',
  code: 'EPIPE',
  syscall: 'write'
}
Error [ERR_IPC_DISCONNECTED]: IPC channel is already disconnected
    at process.target.disconnect (internal/child_process.js:832:26)
    at Worker.<anonymous> (internal/cluster/child.js:208:62)
    at process.onInternalMessage (internal/cluster/utils.js:43:8)
    at process.emit (events.js:228:7)
    at emit (internal/child_process.js:876:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  code: 'ERR_IPC_DISCONNECTED'
}

node v12.15.0
Linux 5.5.6-201.fc31.x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions