Skip to content

"SIGINT" Handlers will be called two times #159

@Zocker1999NET

Description

@Zocker1999NET

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");
});

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