Skip to content

Commit

Permalink
src,http: fix uncaughtException miss in http
Browse files Browse the repository at this point in the history
If the call to MakeCallback is currently in_makecallback() then return
the empty handle instead of Undefined. This allows the error to
propagate through multiple MakeCallback calls.
  • Loading branch information
trevnorris committed Mar 5, 2016
1 parent 01c331e commit cd62963
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/async-wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
}

if (ret.IsEmpty()) {
return Undefined(env()->isolate());
if (callback_scope.in_makecallback())
return ret;
else
return Undefined(env()->isolate());
}

if (has_domain) {
Expand Down
5 changes: 4 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,10 @@ Local<Value> MakeCallback(Environment* env,
}

if (ret.IsEmpty()) {
return Undefined(env->isolate());
if (callback_scope.in_makecallback())
return ret;
else
return Undefined(env->isolate());
}

if (has_domain) {
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-http-catch-uncaughtexception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const http = require('http');

const uncaughtCallback = common.mustCall(function(er) {
assert.equal(er.message, 'get did fail');
});

process.on('uncaughtException', uncaughtCallback);

const server = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('bye');
}).listen(common.PORT, function() {
http.get({ port: common.PORT }, function(res) {
res.resume();
throw new Error('get did fail');
}).on('close', function() {
server.close();
});
});

0 comments on commit cd62963

Please sign in to comment.