mirror of https://github.com/lukechilds/node.git
Browse Source
Previous logic didn't allow parent to propagate to the init callback properly. The fix now allows the init callback to be called and receive the parent if: - async wrap callbacks are enabled and parent exists - the init callback has been called on the parent and an init callback exists then it will be called regardless of whether async wrap callbacks are disabled. Change the init/pre/post callback checks to see if it has been properly set. This allows removal of the Environment "using_asyncwrap" variable. Pass Isolate to a TryCatch instance. Fixes: https://github.com/nodejs/node/issues/2986 PR-URL: https://github.com/nodejs/node/pull/3216 Reviewed-By: Rod Vagg <rod@vagg.org>v4.x
committed by
James M Snell
8 changed files with 131 additions and 40 deletions
@ -0,0 +1,46 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
const common = require('../common'); |
||||
|
const assert = require('assert'); |
||||
|
const net = require('net'); |
||||
|
const async_wrap = process.binding('async_wrap'); |
||||
|
const providers = Object.keys(async_wrap.Providers); |
||||
|
|
||||
|
let cntr = 0; |
||||
|
let server; |
||||
|
let client; |
||||
|
|
||||
|
function init(type, parent) { |
||||
|
if (parent) { |
||||
|
cntr++; |
||||
|
// Cannot assert in init callback or will abort.
|
||||
|
process.nextTick(() => { |
||||
|
assert.equal(providers[type], 'TCPWRAP'); |
||||
|
assert.equal(parent, server._handle, 'server doesn\'t match parent'); |
||||
|
assert.equal(this, client._handle, 'client doesn\'t match context'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function noop() { } |
||||
|
|
||||
|
async_wrap.setupHooks(init, noop, noop); |
||||
|
async_wrap.enable(); |
||||
|
|
||||
|
server = net.createServer(function(c) { |
||||
|
client = c; |
||||
|
// Allow init callback to run before closing.
|
||||
|
setImmediate(() => { |
||||
|
c.end(); |
||||
|
this.close(); |
||||
|
}); |
||||
|
}).listen(common.PORT, function() { |
||||
|
net.connect(common.PORT, noop); |
||||
|
}); |
||||
|
|
||||
|
async_wrap.disable(); |
||||
|
|
||||
|
process.on('exit', function() { |
||||
|
// init should have only been called once with a parent.
|
||||
|
assert.equal(cntr, 1); |
||||
|
}); |
@ -0,0 +1,43 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
const common = require('../common'); |
||||
|
const assert = require('assert'); |
||||
|
const net = require('net'); |
||||
|
const async_wrap = process.binding('async_wrap'); |
||||
|
|
||||
|
let cntr = 0; |
||||
|
let server; |
||||
|
let client; |
||||
|
|
||||
|
function init(type, parent) { |
||||
|
if (parent) { |
||||
|
cntr++; |
||||
|
// Cannot assert in init callback or will abort.
|
||||
|
process.nextTick(() => { |
||||
|
assert.equal(parent, server._handle, 'server doesn\'t match parent'); |
||||
|
assert.equal(this, client._handle, 'client doesn\'t match context'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function noop() { } |
||||
|
|
||||
|
async_wrap.setupHooks(init, noop, noop); |
||||
|
async_wrap.enable(); |
||||
|
|
||||
|
server = net.createServer(function(c) { |
||||
|
client = c; |
||||
|
// Allow init callback to run before closing.
|
||||
|
setImmediate(() => { |
||||
|
c.end(); |
||||
|
this.close(); |
||||
|
}); |
||||
|
}).listen(common.PORT, function() { |
||||
|
net.connect(common.PORT, noop); |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
process.on('exit', function() { |
||||
|
// init should have only been called once with a parent.
|
||||
|
assert.equal(cntr, 1); |
||||
|
}); |
Loading…
Reference in new issue