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

Flag to warn when event loop becomes empty while awaiting a promise, causing the process to exit unexpectedly #35421

Closed
jedwards1211 opened this issue Sep 29, 2020 · 1 comment

Comments

@jedwards1211
Copy link

jedwards1211 commented Sep 29, 2020

Is your feature request related to a problem? Please describe.
I just debugged this really confusing issue with an unexpected exit in Archiver.js: archiverjs/node-archiver#457

The whole time I was thinking, I really wish Node could help me understand why the process is exiting when there are no unhandled rejections and no uncaught errors.

In my app code I was awaiting a promise that was ultimately waiting for the Archiver.js stream to emit an end or error event. But because I forgot to call .finalize() on the archive, it reached a point where it didn't put any new events onto the queue and Node exited with code 0. Which I'm calling a bug with Archiver.js, but the difficulty of debugging bugs like this is a problem. (Just imagine how confused a novice would be about this, when they don't even know about the event loop.)

Describe the solution you'd like
I'm not sure if it's possible, and not sure if there would be unintended consequences to this, but I'm wondering if there's any way for Node to keep track of when a promise is being awaited and warn if it exits due to empty event loop in that case. Or at least a flag to debug unexpected exits in this way?

Describe alternatives you've considered
I was eventually able to figure this issue out by profiling it and realizing I forgot to call .finalize(), but that was after an hour of being utterly confused. If I had been able to run with a switch that would have made it print a warning like process exited because event loop became empty, even though there are unresolved promises, I might have realized sooner what was going on.

@jedwards1211
Copy link
Author

dupe of nodejs/promises-debugging#16

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