Skip to content

Commit 98d262e

Browse files
addaleaxcodebytere
authored andcommittedFeb 27, 2020
src: inform callback scopes about exceptions in HTTP parser
Refs: 4aca277 Refs: #30236 Fixes: #31796 PR-URL: #31801 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com>
1 parent 672f76d commit 98d262e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
 

‎src/node_http_parser.cc

+2
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ class Parser : public AsyncWrap, public StreamListener {
330330
this, InternalCallbackScope::kSkipTaskQueues);
331331
head_response = cb.As<Function>()->Call(
332332
env()->context(), object(), arraysize(argv), argv);
333+
if (head_response.IsEmpty()) callback_scope.MarkAsFailed();
333334
}
334335

335336
int64_t val;
@@ -401,6 +402,7 @@ class Parser : public AsyncWrap, public StreamListener {
401402
InternalCallbackScope callback_scope(
402403
this, InternalCallbackScope::kSkipTaskQueues);
403404
r = cb.As<Function>()->Call(env()->context(), object(), 0, nullptr);
405+
if (r.IsEmpty()) callback_scope.MarkAsFailed();
404406
}
405407

406408
if (r.IsEmpty()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
const common = require('../common');
3+
const asyncHooks = require('async_hooks');
4+
const http = require('http');
5+
6+
// Regression test for https://github.com/nodejs/node/issues/31796
7+
8+
asyncHooks.createHook({
9+
after: () => {}
10+
}).enable();
11+
12+
13+
process.once('uncaughtException', common.mustCall(() => {
14+
server.close();
15+
}));
16+
17+
const server = http.createServer(common.mustCall((request, response) => {
18+
response.writeHead(200, { 'Content-Type': 'text/plain' });
19+
response.end();
20+
}));
21+
22+
server.listen(0, common.mustCall(() => {
23+
http.get({
24+
host: 'localhost',
25+
port: server.address().port
26+
}, common.mustCall(() => {
27+
throw new Error('whoah');
28+
}));
29+
}));

0 commit comments

Comments
 (0)
Please sign in to comment.