Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/node_http_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ class Parser : public AsyncWrap, public StreamListener {
this, InternalCallbackScope::kSkipTaskQueues);
head_response = cb.As<Function>()->Call(
env()->context(), object(), arraysize(argv), argv);
if (head_response.IsEmpty()) callback_scope.MarkAsFailed();
}

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

if (r.IsEmpty()) {
Expand Down
29 changes: 29 additions & 0 deletions test/parallel/test-http-uncaught-from-request-callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';
const common = require('../common');
const asyncHooks = require('async_hooks');
const http = require('http');

// Regression test for https://github.com/nodejs/node/issues/31796

asyncHooks.createHook({
after: () => {}
}).enable();


process.once('uncaughtException', common.mustCall(() => {
server.close();
}));

const server = http.createServer(common.mustCall((request, response) => {
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end();
}));

server.listen(0, common.mustCall(() => {
http.get({
host: 'localhost',
port: server.address().port
}, common.mustCall(() => {
throw new Error('whoah');
}));
}));