-
-
Notifications
You must be signed in to change notification settings - Fork 78
Fatal Error when using async wrap APIs #43
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
Comments
Update: I debugged through this a bit more, and here's what seems to be happening.
function doSomethingAsync() {
// comment out line below to prevent crash
console.log('setting timeout');
...
Net of the above seems to be a cyclic dependency that occurs when loading some module X triggers an async operation and the async-init handler has a dep on that module X. Are there specific things that can be done to fix this? Thanks, Mike |
|
Thanks Andreas. There's effectively a cyclic dependency that occurs when loading a module triggers an AsyncWrap construction (before the module's compilation is completed), the AsyncWrap construction calls the async-wrap init() handler, and the init() handler, having a dep on the (partially compiled) module, attempts to use it. This causes exceptions (probably non-deterministic depending on which parts of the module have been compiled), and code calling the init() handler errors out with a fatal error. The question I have is what is the right fix in the runtime? E.g., can this situation of using a partially-compiled module be detected and "failed fast" with an appropriate error message? Or, is there a more general work-around? (I understand that I can use process._rawDebug and this goes away (or a require('console') before my handlers are hooked in), but these don't address the root cause.) |
/cc @trevnorris |
To make sure we're on the same page, using the nodejs/node#5756 patch the following script works fine for me: 'use strict';
const async_wrap = process.binding('async_wrap');
async_wrap.setupHooks({
init: function init() {
if (console && typeof console.log === 'function')
console.log('hi');
}
});
async_wrap.enable();
setTimeout(() => console.log('foo'), 100); Though excluding the conditional does cause the application to error out because the |
I wasn't suggesting that, but that may not be a bad idea, given that console is widely used for debugging and can easily trigger this behavior. That said, the root cause is more general. Namely, anytime the load of a module X triggers an async operation, and the async init() handler, also tries to load module X, then async init() handler will pick up the partially compiled module. I haven't tried it, but you should be able to repro this with a something other than console. My question here is "what is the right fix"? e.g.,
|
closing old AsyncWrap issues, please start a new thread if appropriate |
Hi -
The program below causes a crash in node (both mac OS w/ node 5.6 & Win Server 2012 R2 with node 5.9).
The Fatal Error is coming from async-wrap-inl.h, lines 57-58.
The exception seems to be getting set in deps/v8/src/ic/ic.cc, lines 654-656, as the passed-in object is undefined.
The stack of the above call (on windows) is the following:
Any help/suggestions appreciated. It's odd that the crash is prevented by calling
doSomethingAsync()
at least once before callingsetupHooks()
anddoSomethingAsync()
a second time. Also, crash is prevented by removing the first console.log statement indoSomethingAsync()
.Thanks,
Mike
The text was updated successfully, but these errors were encountered: