Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 98d262e

Browse filesBrowse files
addaleaxcodebytere
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 <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com>
1 parent 672f76d commit 98d262e
Copy full SHA for 98d262e

File tree

Expand file treeCollapse file tree

2 files changed

+31
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+31
-0
lines changed
Open diff view settings
Collapse file

‎src/node_http_parser.cc‎

Copy file name to clipboardExpand all lines: src/node_http_parser.cc
+2Lines changed: 2 additions & 0 deletions
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()) {
Collapse file
+29Lines changed: 29 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.