-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Loading sql.js in Node makes it terminate the process when unrelated promise rejections are unhandled #421
Comments
This looks like a problem with emscripten. Is this specific to sql.js ? |
I lack the expertise to say but I'll write a tweet and I bet someone will know. |
Looks like it's not specific to sql.js, but it can be configured with a build option. An emscripten issue pointed me to NODEJS_CATCH_REJECTION. From the linked line, it seems clear that building with |
Stated like that, yes, of course. Is there a reason why NODEJS_CATCH_REJECTION=1 is the default? |
emscripten-core/emscripten#9061
// Catch unhandled rejections in node. Without this, node may print the error,
// and that this behavior will change in future node, wait a few seconds, and
// then exit with 0 (which hides the error if you don't read the log). With
// this, we catch any unhandled rejection and throw an actual error, which will
// make the process exit immediately with a non-0 return code.
var NODEJS_CATCH_REJECTION = 1; |
OK, so it seems like it's papering over an issue in emscripten's (or some emscripten-compiled projects') test suites or other command line tools. For a library like sql.js, I think it makes sense to turn this off to avoid changing the entire process' unhandled rejection behavior. Node exiting with 0 status on rejection is a normal (if sometimes inconvenient) part of Node:
but we can always change that behavior with Node arguments when needed:
|
Ok! I agree. Let's change our makefile to include NODEJS_CATCH_REJECTION=0. @garybernhardt, do you want to make the pull request ? |
Done! #423 |
To reproduce: Run this script. It initializes sql.js, waits one second, then creates a rejected promise. The promise is outside of any code related to sql.js. The only relationship is that it's running in the same process.
Expected result: A warning about the rejected promise should be printed by Node, followed by the "process is still alive" message. This is what happens if you comment out the sql.js-related lines:
Actual result: sql.js sees the unhandled rejection in a promise that should be outside of sql.js' control. It aborts the entire Node process:
Discussion: Our application runs sql.js both in the browser and in Node. In the browser, we use it for interactive lessons on SQL. In Node, we use it for automated testing of the lessons.
Some of our code examples in other courses (not the SQL course) intentionally "leak" rejected promises. That test process also loads sql.js during boot, even though it's not in use at the time when rejections are leaked. Merely loading sql.js causes it to intercept the unhandled rejection and abort the Node process.
(The situation seems to be slightly weirder than that in practice. Sometimes unhandled rejections go by without any problems. I haven't been able to detect a pattern. But fortunately the repro code above seems perfectly reliable.)
Versions: We're currently running 1.1.0, but I also upgraded to 1.3.0 (current) and it happened there as well.
The text was updated successfully, but these errors were encountered: