carbone icon indicating copy to clipboard operation
carbone copied to clipboard

[Bug Report]: CTRL+c does not kill the process

Open IlyaRazuvaev opened this issue 3 years ago • 1 comments

Environment Carbone Version: 3.5.5 Node Version: 18.13.0 Desktop OS: tested on "darwin" (Mac), "win32" (Windows 10).

Related issue: https://github.com/carboneio/carbone/issues/179#issuecomment-1480739440

CTRL+c does not kill the process in new version of carbone.

IlyaRazuvaev avatar Apr 20 '23 14:04 IlyaRazuvaev

The issue is due to this addition: https://github.com/carboneio/carbone/blob/master/lib/converter.js#L659 :

['SIGINT', 'SIGHUP', 'SIGQUIT'].forEach(function (signal) {
  process.on(signal, function () {
    converter.exit();
  });
});

According to Nodejs docs, adding listener to those events override default OS behaviour causing the process to hang and never exit: https://nodejs.org/docs/latest-v18.x/api/process.html#signal-events

changing the code to below fixes the issue, and does not break any custom handling for apps that use carbone and require their own custom handling of the signals:

['SIGINT', 'SIGHUP', 'SIGQUIT'].forEach(function (signal) {
    const cleanup = () => {
        converter.exit(() => {
            process.removeListener(signal, cleanup);
            process.kill(process.pid, signal);
        });
    }
    process.on(signal, cleanup);
});

genadis avatar Apr 21 '23 21:04 genadis