Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"SIGINT" Handlers will be called two times #159

Open
Zocker1999NET opened this issue Mar 30, 2019 · 0 comments
Open

"SIGINT" Handlers will be called two times #159

Zocker1999NET opened this issue Mar 30, 2019 · 0 comments

Comments

@Zocker1999NET
Copy link

process.kill(process.pid, 'SIGINT'); // Let other SIGINT handlers run, if there are any

The code line above interferes with another optional handlers for "SIGINT"
by calling them a second time on the first time the signal appears.

This can lead into bugs if a node application depends on less-middleware
and registers handlers for "SIGINT" them self.

The following simulation shows,
that the code line is not needed for other handlers to receive the signal too:
asciicast

Code used in the simulation:

// For closing the app after 5 seconds
setTimeout(() => process.exit(), 5000);

// Simulating handler added before include of less-middleware
let defaultCounter = 0;
process.on("SIGINT", () => {
    defaultCounter++;
    console.log("Default handler called " + defaultCounter + " times");
});

// Simulating handler of less-middleware
process.once("SIGINT", () => {
    console.log("Once handler");
//    process.kill(process.pid, "SIGINT"); // The code interfering
});

// Simulating handler added after include of less-middleware
let secondCounter = 0;
process.on("SIGINT", () => {
    secondCounter++;
    console.log("Second default handler called " + secondCounter + " times");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant