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

if uncaughtExceptionMonitor handler throws asynchronously, the process enters infinite async recursion #38281

Open
MadaraUchiha opened this issue Apr 18, 2021 · 2 comments
Labels
process Issues and PRs related to the process subsystem.

Comments

@MadaraUchiha
Copy link
Contributor

  • Version: v15.14.0
  • Platform: all
  • Subsystem: process/execution

What steps will reproduce the bug?

  1. Register an uncaughtExceptionMonitor handler on process, which itself throws asynchronously
  2. Throw an error

How often does it reproduce? Is there a required condition?

What is the expected behavior?

I'm not sure what should happen here, currently the entire uncaughtException chain is handled synchronously, I'm not certain what adding async to the mix would do. Please advise.

What do you see instead?

Process enters an infinite asynchronous recursion, whereby the monitor invokes the uncaughtRejection which invokes the uncaughtExceptionMonitor and vice versa.

Additional information

Example file:

process.addListener('uncaughtExceptionMonitor', async (e) => {
  console.error('Monitored Error!', e);
  throw new Error('Oopsie!');

});

process.addListener('uncaughtException', e => {
  console.error('Handled error!', e);
})
let i = 0;
setInterval(() => console.log(i++), 1000);
throw new Error('Thrown!');

Output:

...
...
...
Monitored Error! Error: Oopsie!
    at process.<anonymous> (/Users/madara/projects/playground/test.js:3:9)
    at process.emit (node:events:369:20)
    at process._fatalException (node:internal/process/execution:160:13)
    at processPromiseRejections (node:internal/process/promises:245:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:32)
Handled error! Error: Oopsie!
    at process.<anonymous> (/Users/madara/projects/playground/test.js:3:9)
    at process.emit (node:events:369:20)
    at process._fatalException (node:internal/process/execution:160:13)
    at processPromiseRejections (node:internal/process/promises:245:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:32)
Monitored Error! Error: Oopsie!
    at process.<anonymous> (/Users/madara/projects/playground/test.js:3:9)
    at process.emit (node:events:369:20)
    at process._fatalException (node:internal/process/execution:160:13)
    at processPromiseRejections (node:internal/process/promises:245:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:32)
Handled error! Error: Oopsie!
    at process.<anonymous> (/Users/madara/projects/playground/test.js:3:9)
    at process.emit (node:events:369:20)
    at process._fatalException (node:internal/process/execution:160:13)
    at processPromiseRejections (node:internal/process/promises:245:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:32)
^C

(only stops at interrupt)

@MadaraUchiha
Copy link
Contributor Author

My intent is to fix this with a PR, but I'm not sure about the best course of action. Advice would be greatly appreciated <3

@Ayase-252 Ayase-252 added the process Issues and PRs related to the process subsystem. label Apr 18, 2021
@benjamingr
Copy link
Member

add a kCaptureRejections on the listener and if it's coming from uncaughtExceptionMonitor log it (once)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process Issues and PRs related to the process subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants