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

importing edge-runtime breaks process exit behavior #146

Open
EndangeredMassa opened this issue Sep 22, 2022 · 2 comments
Open

importing edge-runtime breaks process exit behavior #146

EndangeredMassa opened this issue Sep 22, 2022 · 2 comments

Comments

@EndangeredMassa
Copy link

If I import the edge runtime, then my process has an uncaught exception, my process exits with no error message and an exit code of 0.

Reproduction: https://github.com/EndangeredMassa/reproduction-process-exit-behavior

Example:

import { EdgeRuntime } from 'edge-runtime';

throw new Error('intentional break');

It seems that these lines are the cause:

/**
* Define system-level handlers to make sure that we report to the user
* whenever there is an unhandled rejection or exception before the process crashes.
*/
process.on(
'unhandledRejection',
function invokeRejectionHandlers(reason, promise) {
unhandledRejectionHandlers?.forEach((handler) => handler(reason, promise))
}
)
process.on('uncaughtException', function invokeErrorHandlers(error) {
uncaughtExceptionHandlers?.forEach((handler) => handler(error))
})

@feugy
Copy link
Member

feugy commented Sep 29, 2022

Hey @EndangeredMassa! Thank you for this.

@javivelasco and I did a bit of analysis.

The reason why we caught exceptions & rejections at process level within EdgeRuntime is to avoid exiting the runtime itself. This way, the runtime is resilient to exception/rejections occurring within the executed user code.
Instead, it reports them using events, allowing caller code to gracefully handle them

But this creates that undesirable side you demonstrated: the simple import of the EdgeRuntime swallows everything! Very bad.

Our plan is the following:

  • make a distinction between errors happening during user code execution, and at process level
  • for the first error group, keep the current behavior (no exit, call event handlers instead)
  • for the second error group, propagate the error, so it stops and sets exit code

How does it sounds to you?

@EndangeredMassa
Copy link
Author

That sounds good to me, thanks!

feugy added a commit that referenced this issue Dec 13, 2022
javivelasco pushed a commit that referenced this issue Dec 13, 2022
jridgewell pushed a commit to jridgewell/edge-runtime that referenced this issue Jun 23, 2023
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

2 participants