Skip to content

Hook does not finish executing in worker process #11

@ghost

Description

Let me illustrate the problem with the following code:

const cluster = require("cluster");
const exitHook = require("async-exit-hook");

function addHook(delay) {
    exitHook(cb => {
        console.log("Start " + delay);
        setTimeout(() => {
            console.log("Finish " + delay);
            cb()
        }, delay);
    });
}

if (cluster.isMaster) {
    cluster.fork();
} else {
    addHook(0);
    addHook(1);
    addHook(10);
    addHook(100);
}

If I start this script and kill it with ctrl+c, then I get:

$ node exitHook.js
^C
$ Start 0
Start 1
Start 10
Start 100
Finish 0
Finish 1

As you can see, only the very fast exit hooks are executed. This problem only happens in workers. Is this a known issue?

Versions:

  • Node: v10.16.3 and v12.8.0
  • Async exit hook: 2.0.1
  • Operating system: Ubuntu 18.04.1 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions