Skip to content

Commit

Permalink
src: don't call into VM from AsyncWrap destructor
Browse files Browse the repository at this point in the history
It is not allowed anymore to call JS code when collecting weakly
persistent handles, it hits the assertion below:

    # Fatal error in ../deps/v8/src/execution.cc, line 103
    # Check failed: AllowJavascriptExecution::IsAllowed(isolate).

Remove the call into the VM from the AsyncWrap destructor.  This commit
breaks the destroy hook but that cannot be helped.

Fixes: nodejs#8216
  • Loading branch information
bnoordhuis committed Nov 4, 2016
1 parent 7537718 commit 7206606
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 30 deletions.
18 changes: 1 addition & 17 deletions src/async-wrap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,7 @@ inline AsyncWrap::AsyncWrap(Environment* env,
}


inline AsyncWrap::~AsyncWrap() {
if (!ran_init_callback())
return;

v8::Local<v8::Function> fn = env()->async_hooks_destroy_function();
if (!fn.IsEmpty()) {
v8::HandleScope scope(env()->isolate());
v8::Local<v8::Value> uid = v8::Number::New(env()->isolate(), get_uid());
v8::TryCatch try_catch(env()->isolate());
v8::MaybeLocal<v8::Value> ret =
fn->Call(env()->context(), v8::Null(env()->isolate()), 1, &uid);
if (ret.IsEmpty()) {
ClearFatalExceptionHandlers(env());
FatalException(env()->isolate(), try_catch);
}
}
}
inline AsyncWrap::~AsyncWrap() {}


inline bool AsyncWrap::ran_init_callback() const {
Expand Down
8 changes: 2 additions & 6 deletions test/parallel/test-async-wrap-throw-from-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const assert = require('assert');
const crypto = require('crypto');
const domain = require('domain');
const spawn = require('child_process').spawn;
const callbacks = [ 'init', 'pre', 'post', 'destroy' ];
const callbacks = [ 'init', 'pre', 'post' ];
const toCall = process.argv[2];
var msgCalled = 0;
var msgReceived = 0;
Expand All @@ -28,13 +28,9 @@ function post() {
if (toCall === 'post')
throw new Error('post');
}
function destroy() {
if (toCall === 'destroy')
throw new Error('destroy');
}

if (typeof process.argv[2] === 'string') {
async_wrap.setupHooks({ init, pre, post, destroy });
async_wrap.setupHooks({ init, pre, post });
async_wrap.enable();

process.on('uncaughtException', () => assert.ok(0, 'UNREACHABLE'));
Expand Down
8 changes: 1 addition & 7 deletions test/parallel/test-async-wrap-uid.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ const assert = require('assert');
const async_wrap = process.binding('async_wrap');

const storage = new Map();
async_wrap.setupHooks({ init, pre, post, destroy });
async_wrap.setupHooks({ init, pre, post });
async_wrap.enable();

function init(uid) {
storage.set(uid, {
init: true,
pre: false,
post: false,
destroy: false
});
}

Expand All @@ -26,10 +25,6 @@ function post(uid) {
storage.get(uid).post = true;
}

function destroy(uid) {
storage.get(uid).destroy = true;
}

fs.access(__filename, function(err) {
assert.ifError(err);
});
Expand All @@ -51,7 +46,6 @@ process.once('exit', function() {
init: true,
pre: true,
post: true,
destroy: true
});
}
});

0 comments on commit 7206606

Please sign in to comment.