Skip to content

Commit 7c3c062

Browse files
ronagaddaleax
authored andcommitted
http: don't emit 'readable' after 'close'
PR-URL: #32277 Refs: #28710 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 6d4d299 commit 7c3c062

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

lib/_http_server.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,12 @@ function clearIncoming(req) {
665665
if (parser && parser.incoming === req) {
666666
if (req.readableEnded) {
667667
parser.incoming = null;
668+
req.emit('close');
668669
} else {
669670
req.on('end', clearIncoming);
670671
}
672+
} else {
673+
req.emit('close');
671674
}
672675
}
673676

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

680683
state.incoming.shift();
681-
clearIncoming(req);
682684

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

689691
res.detachSocket(socket);
690-
req.emit('close');
692+
clearIncoming(req);
691693
process.nextTick(emitCloseNT, res);
692694

693695
if (res._last) {

test/parallel/test-async-hooks-http-parser-destroy.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const async_hooks = require('async_hooks');
55
const http = require('http');
@@ -45,6 +45,9 @@ async_hooks.createHook({
4545
}).enable();
4646

4747
const server = http.createServer((req, res) => {
48+
req.on('close', common.mustCall(() => {
49+
req.on('readable', common.mustNotCall());
50+
}));
4851
res.end('Hello');
4952
});
5053

test/parallel/test-http-no-read-no-dump.js

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ const server = http.createServer((req, res) => {
1111
res.writeHead(200);
1212
res.flushHeaders();
1313

14+
req.on('close', common.mustCall(() => {
15+
req.on('end', common.mustNotCall());
16+
}));
17+
1418
req.connection.on('pause', () => {
1519
res.end();
1620
onPause();

0 commit comments

Comments
 (0)