-
Notifications
You must be signed in to change notification settings - Fork 236
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
abortHook does not work inside async function #1186
Comments
Interesting behavior. The problem is more subtle than it first appears. First, the abortHook is called if the exception is thrown at the root -- e.g. instead of calling From the timer, the abortHook is called too, once a garbage collection occurs. To see that, include the Debug module in your project's manifest ( import Debug from "debug"
Timer.set(() => {
trace("timer tick & gc\n");
Debug.gc();
}, 2000) You'll see this output:
In a real project (not a simple test case) GC generally happen frequently enough that the unhandled rejection will be reported reasonably soon after occurring. I'm not yet sure what it would take to report the unhanded rejection sooner. That will take some further investigation. |
GC works, I adding this code into the test:
And got the stack trace back (soon enough) @phoddie you may want to add a link to this discussion into the sample code? |
Cool. At a minimum, it is a workaround.
Good suggestion, thank you. Before doing that, I'd like to investigate whether there is a way to avoid the need for the GC here. |
The reason that the unhanded rejection is not reported until after a garbage collection is because of a feature of Promises: it is possible to attach the rejection handler after the promise is rejected. As a result, the engine can only consider the rejection as unhandled when there are no more references to it. Here's an example that shows a rejection handler being assigned after the promise is rejected. XS traces "oops" here as expected rather than reporting a rejected promise. import Timer from "timer"
async function throwError() {
throw "oops"
}
let promise = null;
Timer.set(() => {
promise = throwError()
}, 1000)
Timer.set(() => {
promise.catch(error => {
trace(error, "\n")
});
promise = null;
}, 2000) |
Description
abortHook does not work when the exception is from async function
Steps to Reproduce
Expected behavior
(by removing the
async
keyword of throw Error() function)The board reboots after the error
Actual behavior
The board does NOT reboot after the error
When an error is thrown inside an async function, the abortHook does not get called, and the code continues to execute. This can be dangerous as the code may run into some uncontrolled states.
Also, I tried if using -d build and test with debugger, the debugger does break when error throwing.
And a few more words about the abortHook:
I believe that being able to capture and diagnose problems in a production environment is crucial. In general, when a program crashes, we should:
The text was updated successfully, but these errors were encountered: