Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions test/parallel/test-async-hooks-http-parser-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ async_hooks.createHook({
}).enable();

const server = http.createServer((req, res) => {
let closed = false;
req.on('close', () => {
closed = true;
});
req.on('readable', () => {
assert.strictEqual(closed, false);
});
res.end('Hello');
});

Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-http-no-read-no-dump.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const common = require('../common');
const http = require('http');
const assert = require('assert');

let onPause = null;

Expand All @@ -11,6 +12,14 @@ const server = http.createServer((req, res) => {
res.writeHead(200);
res.flushHeaders();

let closed = false;
req.on('close', common.mustCall(() => {
closed = true;
}));
req.on('end', common.mustCall(() => {
assert.strictEqual(closed, false);
}));

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