http: don't emit 'readable' after 'close'

PR-URL: https://github.com/nodejs/node/pull/32277
Refs: https://github.com/nodejs/node/issues/28710
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Robert Nagy authored and Anna Henningsen committed 2020-03-30 10:22:11 +02:00
1 parent 19db0e60bd
commit e034f5c3d9
3 files changed
+12 -3

No files matched your search

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