src: inform callback scopes about exceptions in HTTP parser

Refs: https://github.com/nodejs/node/commit/4aca277f16b8649b5fc21d41f340fad0a47c2e61
Refs: https://github.com/nodejs/node/pull/30236
Fixes: https://github.com/nodejs/node/issues/31796

PR-URL: https://github.com/nodejs/node/pull/31801
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
This commit is contained in:
Anna Henningsen authored and Myles Borins committed 2020-02-17 20:57:56 -05:00
1 parent a5bc00af12
commit 42b68a4e24
2 files changed
+31

No files matched your search

+2
View File
@@ -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');
}));
}));