-
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.
src: fix domains + --abort-on-uncaught-exception
If run with --abort-on-uncaught-exception, V8 will abort the process whenever it does not see a JS-installed CatchClause in the stack. C++ TryCatch clauses are ignored. Domains work by setting a FatalException handler which is ignored when running in abort mode. This patch modifies MakeCallback to call its target function through a JS function that installs a CatchClause and manually calls _fatalException on error, if the process is both using domains and is in abort mode. Semver: patch PR-URL: #922 Fixes: #836 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
- Loading branch information
1 parent
2ca22aa
commit 0af4c9e
Showing
6 changed files
with
154 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var spawn = require('child_process').spawn; | ||
|
||
var tests = [ | ||
nextTick, | ||
timer, | ||
timerPlusNextTick, | ||
firstRun, | ||
netServer | ||
] | ||
|
||
tests.forEach(function(test) { | ||
console.log(test.name); | ||
var child = spawn(process.execPath, [ | ||
'--abort-on-uncaught-exception', | ||
'-e', | ||
'(' + test + ')()', | ||
common.PORT | ||
]); | ||
child.stderr.pipe(process.stderr); | ||
child.stdout.pipe(process.stdout); | ||
child.on('exit', function(code) { | ||
assert.strictEqual(code, 0); | ||
}); | ||
}); | ||
|
||
function nextTick() { | ||
var domain = require('domain'); | ||
var d = domain.create(); | ||
|
||
d.on('error', function(err) { | ||
console.log('ok'); | ||
process.exit(0); | ||
}); | ||
d.run(function() { | ||
process.nextTick(function() { | ||
throw new Error('exceptional!'); | ||
}); | ||
}); | ||
} | ||
|
||
function timer() { | ||
var domain = require('domain'); | ||
var d = domain.create(); | ||
|
||
d.on('error', function(err) { | ||
console.log('ok'); | ||
process.exit(0); | ||
}); | ||
d.run(function() { | ||
setTimeout(function() { | ||
throw new Error('exceptional!'); | ||
}, 33); | ||
}); | ||
} | ||
|
||
function timerPlusNextTick() { | ||
var domain = require('domain'); | ||
var d = domain.create(); | ||
|
||
d.on('error', function(err) { | ||
console.log('ok'); | ||
process.exit(0); | ||
}); | ||
d.run(function() { | ||
setTimeout(function() { | ||
process.nextTick(function() { | ||
throw new Error('exceptional!'); | ||
}); | ||
}, 33); | ||
}); | ||
} | ||
|
||
function firstRun() { | ||
var domain = require('domain'); | ||
var d = domain.create(); | ||
|
||
d.on('error', function(err) { | ||
console.log('ok'); | ||
process.exit(0); | ||
}); | ||
d.run(function() { | ||
throw new Error('exceptional!'); | ||
}); | ||
} | ||
|
||
function netServer() { | ||
var domain = require('domain'); | ||
var net = require('net'); | ||
var d = domain.create(); | ||
|
||
d.on('error', function(err) { | ||
console.log('ok'); | ||
process.exit(0); | ||
}); | ||
d.run(function() { | ||
var server = net.createServer(function(conn) { | ||
conn.pipe(conn); | ||
}); | ||
server.listen(Number(process.argv[1]), '0.0.0.0', function() { | ||
var conn = net.connect(Number(process.argv[1]), '0.0.0.0') | ||
conn.once('data', function() { | ||
throw new Error('ok'); | ||
}) | ||
conn.end('ok'); | ||
}); | ||
}); | ||
} |
0af4c9e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it intentional not to place the same check in
node::MakeCallback()
?0af4c9e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, yes, I think I missed that.