Skip to content

Commit

Permalink
src: inform callback scopes about exceptions in HTTP parser
Browse files Browse the repository at this point in the history
Refs: 4aca277
Refs: #30236
Fixes: #31796

PR-URL: #31801
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
  • Loading branch information
addaleax committed Feb 18, 2020
1 parent eb0ade1 commit fab3eff
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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');
}));
}));

0 comments on commit fab3eff

Please sign in to comment.