-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
async_wrap: don't abort on callback exception
Rather than abort if the init/pre/post/final/destroy callbacks throw, force the exception to propagate and not be made catchable. This way the application is still not allowed to proceed but also allowed the location of the failure to print before exiting. Though the stack itself may not be of much use since all callbacks except init are called from the bottom of the call stack. /tmp/async-test.js:14 throw new Error('pre'); ^ Error: pre at InternalFieldObject.pre (/tmp/async-test.js:14:9) PR-URL: #5756 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Andreas Madsen <[email protected]>
- Loading branch information
1 parent
6f16882
commit 2cbbaaf
Showing
5 changed files
with
134 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const async_wrap = process.binding('async_wrap'); | ||
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 toCall = process.argv[2]; | ||
var msgCalled = 0; | ||
var msgReceived = 0; | ||
|
||
function init() { | ||
if (toCall === 'init') | ||
throw new Error('init'); | ||
} | ||
function pre() { | ||
if (toCall === 'pre') | ||
throw new Error('pre'); | ||
} | ||
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.enable(); | ||
|
||
process.on('uncaughtException', () => assert.ok(0, 'UNREACHABLE')); | ||
|
||
const d = domain.create(); | ||
d.on('error', () => assert.ok(0, 'UNREACHABLE')); | ||
d.run(() => { | ||
// Using randomBytes because timers are not yet supported. | ||
crypto.randomBytes(0, () => { }); | ||
}); | ||
|
||
} else { | ||
|
||
process.on('exit', (code) => { | ||
assert.equal(msgCalled, callbacks.length); | ||
assert.equal(msgCalled, msgReceived); | ||
}); | ||
|
||
callbacks.forEach((item) => { | ||
msgCalled++; | ||
|
||
const child = spawn(process.execPath, [__filename, item]); | ||
var errstring = ''; | ||
|
||
child.stderr.on('data', (data) => { | ||
errstring += data.toString(); | ||
}); | ||
|
||
child.on('close', (code) => { | ||
if (errstring.includes('Error: ' + item)) | ||
msgReceived++; | ||
|
||
assert.equal(code, 1, `${item} closed with code ${code}`); | ||
}); | ||
}); | ||
} |