mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00:00
http: remove 'data' and 'end' listener if client parser error
There might be the case of some more data coming through after the parser has returned an error and we have destroyed the socket. We should also be removing the 'data' event handler. Fixes: https://github.com/nodejs/node/issues/40242 PR-URL: https://github.com/nodejs/node/pull/40244 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
4f3eda66cc
commit
140b25a35f
@ -489,6 +489,8 @@ function socketOnData(d) {
|
||||
prepareError(ret, parser, d);
|
||||
debug('parse error', ret);
|
||||
freeParser(parser, req, socket);
|
||||
socket.removeListener('data', socketOnData);
|
||||
socket.removeListener('end', socketOnEnd);
|
||||
socket.destroy();
|
||||
req.socket._hadError = true;
|
||||
req.emit('error', ret);
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
const common = require('../common');
|
||||
const http = require('http');
|
||||
const net = require('net');
|
||||
const assert = require('assert');
|
||||
const Countdown = require('../common/countdown');
|
||||
|
||||
const countdown = new Countdown(2, () => server.close());
|
||||
@ -38,10 +39,12 @@ const server =
|
||||
|
||||
server.listen(0, common.mustCall(() => {
|
||||
for (let i = 0; i < 2; i++) {
|
||||
http.get({
|
||||
const req = http.get({
|
||||
port: server.address().port,
|
||||
path: '/'
|
||||
}).on('error', common.mustCall((e) => {
|
||||
assert.strictEqual(req.socket.listenerCount('data'), 0);
|
||||
assert.strictEqual(req.socket.listenerCount('end'), 1);
|
||||
common.expectsError({
|
||||
code: 'HPE_INVALID_CONSTANT',
|
||||
message: 'Parse Error: Expected HTTP/'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user