-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
debug: unhandled exception from runInDebugContext causes segfault #1190
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Here's a patch that fixes the segfault diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index 6985a33..1a8bd07 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -233,10 +233,14 @@ class ContextifyContext {
static void RunInDebugContext(const FunctionCallbackInfo<Value>& args) {
+ // TODO(ofrobots): maybe only do this once
+ Local<Context> context = Debug::GetDebugContext();
+ Environment::GetCurrent(args)->AssignToContext(context);
+
Local<String> script_source(args[0]->ToString(args.GetIsolate()));
if (script_source.IsEmpty())
return; // Exception pending.
- Context::Scope context_scope(Debug::GetDebugContext());
+ Context::Scope context_scope(context);
Local<Script> script = Script::Compile(script_source);
if (script.IsEmpty())
return; // Exception pending. However, don't go merging it just yet. While the simplified test-case (above) does get fixed, the following slightly bigger test-case (that is closer to what I am trying to do) still segfaults. var vm = require('vm');
var Debug = vm.runInDebugContext('Debug');
Debug.setListener(function(evt, execState, eventData) {
console.log('debug event ' + evt);
if (evt === 1) {
var mirror = execState.frame(0).evaluate('process.env');
console.log(mirror.properties());
}
});
debugger; This segfaults in a similar way: $ ~/src/io.js/iojs test2.js
debug event 1
debug event 5
[1] 85147 segmentation fault ~/src/io.js/iojs ~/src/test/test2.js I suspect that there is yet another context active at this point. The crash occurs on Here's what I think we need to do:
@indutny thoughts? |
This is related to nodejs/node-v0.x-archive#9156. I am trying to come up with a solution. |
@bnoordhuis Looking at commit 756b622, you might have some, ehm, context about this problem too. There are a bunch of contexts at play here. At the time We never had an opportunity to Assign Here's my question: wouldn't it make more sense for node to associate Perhaps the fix is to store the Environment into Let me know if this makes sense. I can send a PR. |
Ensure that the debug context has an Environment assigned in case a fatal error is raised. The fatal exception handler in node.cc is not equipped to deal with contexts that don't have one and can't easily be taught that due to a deficiency in the V8 API: there is no way for the embedder to tell if the data index is in use. Fixes: nodejs#1190 PR-URL: nodejs#1229 Reviewed-By: Fedor Indutny <fedor@indutny.com>
Thanks for the bug report, should be fixed by cf081a4. |
The second testcase I posted still fails even with your fix. $ ./iojs_g ~/src/test/test2.js
debug event 1
debug event 5
FATAL ERROR: v8::Context::GetAlignedPointerFromEmbedderData() Index too large The testcase is in #1190 (comment). |
I'm not sure I agree that qualifies as an io.js bug. Let me adapt the test so it's a little easier to talk about: require('vm').runInDebugContext('Debug').setListener(ondebugevent);
function ondebugevent(evt, exc) {
if (evt === 1) exc.frame(0).evaluate('process.env').properties();
}
function breakpoint() { debugger; }
breakpoint();
Anyway, that's why it segfaults, because ( But whatever, I think we can work around this quirk with a little effort. I'll open a PR in a few. |
It's possible for an accessor or named interceptor to get called with a different execution context than the one it lives in, see the test case for an example using the debug API. This commit fortifies against that by passing the environment as a data property instead of looking it up through the current context. Fixes: nodejs#1190 (again) PR-URL: nodejs#1238 Reviewed-By: Fedor Indutny <fedor@indutny.com>
Fixed again in 7e88a93. Please file new issues if this turns into a bug whack-a-mole. |
Awesome! Thanks a lot for fixing. |
The following test-case causes a segfault:
With a debug build:
I think that the issue is that node::Environment has not been initialized for the debug context.
Here's a (truncated) stack-trace from the debug build:
Frame 9 is trying to get the node::Environment from the debug context, but that is going to fail, since we never Set EmbedderData in that Context.
Wrapping the test case in a try/catch works around the issue.
I tested with 1.5.2, 1.1.0 and 0.12.0. All of them crash as above.
The text was updated successfully, but these errors were encountered: