Giter Club home page Giter Club logo

async-exit-hook's People

Contributors

mvayngrib avatar qcgm1978 avatar sindresorhus avatar tapppi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

async-exit-hook's Issues

pm2 stop do not trigger the hook

run nodejs app as:
pm2 start app.js
it run successfully. Then I tried to stop app:
pm2 stop id

But it can not trigger exitHook()

Hook does not finish executing in worker process

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

Error thrown in `exitHook` is not handled causing zombie process

The runHook method has no error handling:

if (err) {
  // Pass error, calling uncaught exception handlers
  return hook(err, stepTowardExit);
}
return hook(stepTowardExit);

If a hook throws, then the exit procedure stops and exit is never actually achieved. (I found this by hitting #9 which threw in an exit routine.)

This could be fixed by wrapping in a try/catch and calling stepTowardsExit on error.

Add weight optional param to exit hook

This would be useful to control the order of exit hooks execution where required. Use case: if I am using it for shutting down dependant processes gracefully, I am probably expecting to have logging being shut down as last.

How send email on exit?

Please, could you provide an example of how use NodeMailer to send an email on Node exit? I can't figure it out how to integrate callback with nodemailer's promise. Thanks.

Broken API Contract

When calling exit hook, like so:

exitHook(cb => { /* do something on exit */ })

cb may not be a function depending on how the async-exit-hook routine is entered. If it's entered with an uncaught error, then it's called with 2 params and the second is the callback.

if (exit && hook.length > syncArgCount) {
  // Hook is async, expects a finish callback
  waitingFor++;

  if (err) {
    // Pass error, calling uncaught exception handlers
   return hook(err, stepTowardExit); // call called with 2 params
  }
  return hook(stepTowardExit); // <-- called with 1 param
}

This would be easy to fix by simply changing the second to:

return hook(null, stepTowardExit);

Because this is a breaking change to the API, it probably warrants a major version upgrade.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.