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 authored and MylesBorins committed Feb 18, 2020
1 parent a5bc00a commit 42b68a4
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_impl.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
29 changes: 29 additions & 0 deletions test/parallel/test-http-uncaught-from-request-callback.js
@@ -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.