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
6 changes: 4 additions & 2 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,12 @@ function clearIncoming(req) {
if (parser && parser.incoming === req) {
if (req.readableEnded) {
parser.incoming = null;
req.emit('close');
} else {
req.on('end', clearIncoming);
}
} else {
req.emit('close');
}
}

Expand All @@ -678,7 +681,6 @@ function resOnFinish(req, res, socket, state, server) {
assert(state.incoming.length === 0 || state.incoming[0] === req);

state.incoming.shift();
clearIncoming(req);

// If the user never called req.read(), and didn't pipe() or
// .resume() or .on('data'), then we call req._dump() so that the
Expand All @@ -687,7 +689,7 @@ function resOnFinish(req, res, socket, state, server) {
req._dump();

res.detachSocket(socket);
req.emit('close');
clearIncoming(req);
process.nextTick(emitCloseNT, res);

if (res._last) {
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-async-hooks-http-parser-destroy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');
const http = require('http');
Expand Down Expand Up @@ -45,6 +45,9 @@ async_hooks.createHook({
}).enable();

const server = http.createServer((req, res) => {
req.on('close', common.mustCall(() => {
req.on('readable', common.mustNotCall());
}));
res.end('Hello');
});

Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-http-no-read-no-dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const server = http.createServer((req, res) => {
res.writeHead(200);
res.flushHeaders();

req.on('close', common.mustCall(() => {
req.on('end', common.mustNotCall());
}));

req.connection.on('pause', () => {
res.end();
onPause();
Expand Down