Skip to content
Permalink
Browse files

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>
  • Loading branch information
addaleax authored and MylesBorins committed Feb 14, 2020
1 parent a5bc00a commit 42b68a4e243c863172e31f75222fbee89509c4ec
Showing with 31 additions and 0 deletions.
  1. +2 −0 src/node_http_parser_impl.h
  2. +29 −0 test/parallel/test-http-uncaught-from-request-callback.js
@@ -340,6 +340,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;
@@ -413,6 +414,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()) {
@@ -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 42b68a4

Please sign in to comment.
You can’t perform that action at this time.