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 defined in app are not executed #192

Closed
alexandervain opened this issue Apr 21, 2019 · 6 comments · May be fixed by mike-north/devcert#45 or sekikn/avro#9
Closed

SIGINT handlers defined in app are not executed #192

alexandervain opened this issue Apr 21, 2019 · 6 comments · May be fixed by mike-north/devcert#45 or sekikn/avro#9
Assignees
Labels

Comments

@alexandervain
Copy link

Operating System

  • MacOS
  • Linux

NodeJS Version

  • 10.15.3

Tmp Version

  • 0.1.0

Expected Behavior

Allow executing app defined SIGINT handlers

Experienced Behavior

App exits before custom handlers are executed.

Here is the reason: /~https://github.com/raszi/node-tmp/blob/master/lib/tmp.js#L635
Code to reproduce:

const tmp = require('tmp');
console.log(`Run from terminal: kill -SIGINT ${process.pid}`);

process.on('SIGINT', () => {
    console.log('Custom SIGINT handler - do some clean up')
    process.exit(0);
});

setTimeout(() => {}, 100000)

Custom SIGINT handler - do some clean up not printed.

The same code works OK with tmp@0.0.33

@silkentrance
Copy link
Collaborator

@alexandervain Very good find. This always went unnoticed in the tests as we do not have any custom SIGINT handlers installed. I wonder why the routine even checks the doExit parameter...
I think that this can be removed completely.

@silkentrance
Copy link
Collaborator

Ok, the doExit was there for a reason, having to do with jest and how it is managing its sandboxes, which eventually will run the initialising code of tmp multiple times.

I think I have nailed it down and will prepare a PR now.

@alubbe
Copy link

alubbe commented Jun 3, 2019

@alexandervain @papandreou Does this commit fix the bug? df8df51

facebook-github-bot pushed a commit to facebook/flipper that referenced this issue Jul 10, 2019
Summary:
The SIGINT handler in headless was being squashed by the one that `tmp` adds. This is a bug introduced in its latest release: raszi/node-tmp#192

Downgrading version to fix this for now. There's a PR to fix it, we can upgrade when it's shipped.

Reviewed By: passy

Differential Revision: D16163208

fbshipit-source-id: 058ec1094dd2e5e5474f7ac36be376bae0431f0c
@eugene1g
Copy link

eugene1g commented Sep 8, 2019

There is also the case of async handlers - we have process.on() handlers that return promise, and NodeJS will wait for those promises to resolve before existing. As I understand df8df51, it will call original handlers in a sync matter, which will not give async functions enough time to complete.

@Tyler-Murphy
Copy link

Tyler-Murphy commented Sep 25, 2019

@alubbe, I encountered the same bug while doing asynchronous operations in a SIGINT event listener. It was fixed by df8df51.

@alubbe
Copy link

alubbe commented Sep 25, 2019

sounds good - how about merging #193 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants