Skip to content

Commit 42b68a4

Browse files
addaleaxMylesBorins
authored andcommitted
src: inform callback scopes about exceptions in HTTP parser
Refs: 4aca277 Refs: #30236 Fixes: #31796 PR-URL: #31801 Reviewed-By: James M Snell <[email protected]> Reviewed-By: David Carlier <[email protected]>
1 parent a5bc00a commit 42b68a4

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/node_http_parser_impl.h

+2
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ class Parser : public AsyncWrap, public StreamListener {
340340
this, InternalCallbackScope::kSkipTaskQueues);
341341
head_response = cb.As<Function>()->Call(
342342
env()->context(), object(), arraysize(argv), argv);
343+
if (head_response.IsEmpty()) callback_scope.MarkAsFailed();
343344
}
344345

345346
int64_t val;
@@ -413,6 +414,7 @@ class Parser : public AsyncWrap, public StreamListener {
413414
InternalCallbackScope callback_scope(
414415
this, InternalCallbackScope::kSkipTaskQueues);
415416
r = cb.As<Function>()->Call(env()->context(), object(), 0, nullptr);
417+
if (r.IsEmpty()) callback_scope.MarkAsFailed();
416418
}
417419

418420
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)