Skip to content

cluster: suicide flag is not set on master when calling disconnect from a worker #3238

Closed
@dpatti

Description

@dpatti

From the documentation:

worker.suicide:

Set by calling .kill() or .disconnect(), until then it is undefined.

worker.disconnect():

In a worker, this function will close all servers, wait for the 'close' event on those servers, and then disconnect the IPC channel.

Causes .suicide to be set.

Repro:

var cluster = require('cluster');

if (cluster.isMaster) {
  // Master forks and listens for events
  var worker = cluster.fork();
  cluster.on('disconnect', function(){
    console.log("disconnect", worker.suicide);
  });
  cluster.on('exit', function(){
    console.log("exit", worker.suicide);
  });
} else {
  // Worker just disconnects
  cluster.worker.disconnect();
}

In node v0.10, both log statements would print true for worker.suicide. In 41b75ca, which landed during the v0.11 branch, this was broken, and all versions up to node v4 will print false. This is because worker.disconnect(), when called from the worker, does not send the suicide message anymore -- only worker.destroy() will send that message to the master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clusterIssues and PRs related to the cluster subsystem.confirmed-bugIssues with confirmed bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions