Skip to content

Commit cd62963

Browse files
committed
src,http: fix uncaughtException miss in http
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.
1 parent 01c331e commit cd62963

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/async-wrap.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
220220
}
221221

222222
if (ret.IsEmpty()) {
223-
return Undefined(env()->isolate());
223+
if (callback_scope.in_makecallback())
224+
return ret;
225+
else
226+
return Undefined(env()->isolate());
224227
}
225228

226229
if (has_domain) {

src/node.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,10 @@ Local<Value> MakeCallback(Environment* env,
11851185
}
11861186

11871187
if (ret.IsEmpty()) {
1188-
return Undefined(env->isolate());
1188+
if (callback_scope.in_makecallback())
1189+
return ret;
1190+
else
1191+
return Undefined(env->isolate());
11891192
}
11901193

11911194
if (has_domain) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const http = require('http');
6+
7+
const uncaughtCallback = common.mustCall(function(er) {
8+
assert.equal(er.message, 'get did fail');
9+
});
10+
11+
process.on('uncaughtException', uncaughtCallback);
12+
13+
const server = http.createServer(function(req, res) {
14+
res.writeHead(200, { 'Content-Type': 'text/plain' });
15+
res.end('bye');
16+
}).listen(common.PORT, function() {
17+
http.get({ port: common.PORT }, function(res) {
18+
res.resume();
19+
throw new Error('get did fail');
20+
}).on('close', function() {
21+
server.close();
22+
});
23+
});

0 commit comments

Comments
 (0)