-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
async_wrap: correctly pass parent to init callback
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: #2986 PR-URL: #3216 Reviewed-By: Rod Vagg <[email protected]>
- Loading branch information
1 parent
28aac7f
commit 3eaa593
Showing
8 changed files
with
131 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
test/parallel/test-async-wrap-disabled-propagate-parent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |