Skip to content

Commit c9dc0a8

Browse files
islandryuRafaelGSS
authored andcommitted
http: fix keep-alive not timing out after post-request empty line
Fixes: #58140 PR-URL: #58178 Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 4c2c100 commit c9dc0a8

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

lib/_http_server.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,8 +918,6 @@ function socketOnError(e) {
918918
}
919919

920920
function onParserExecuteCommon(server, socket, parser, state, ret, d) {
921-
resetSocketTimeout(server, socket, state);
922-
923921
if (ret instanceof Error) {
924922
prepareError(ret, parser, d);
925923
debug('parse error', ret);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as common from '../common/index.mjs';
2+
import assert from 'node:assert';
3+
import { createServer } from 'node:http';
4+
import { connect } from 'node:net';
5+
6+
const server = createServer({
7+
connectionsCheckingInterval: 100,
8+
headersTimeout: 100,
9+
keepAliveTimeout: 300
10+
}, (req, res) => {
11+
res.writeHead(404);
12+
res.end();
13+
14+
req.socket.on('close', common.mustCall(() => {
15+
server.close();
16+
}));
17+
});
18+
19+
server.listen(0, () => {
20+
const client = connect({
21+
host: 'localhost',
22+
port: server.address().port,
23+
}, () => {
24+
client.write(
25+
'GET / HTTP/1.1\r\n' +
26+
'Host: localhost:3000\r\n' +
27+
'Content-Length: 0\r\n' +
28+
'\r\n'
29+
);
30+
31+
setTimeout(() => {
32+
client.write('\r\n');
33+
}, 100);
34+
35+
let responseBuffer = '';
36+
37+
client.on('data', (chunk) => {
38+
responseBuffer += chunk.toString();
39+
40+
// Check if we've received the full header (ending with \r\n\r\n)
41+
if (responseBuffer.includes('\r\n\r\n')) {
42+
const statusLine = responseBuffer.split('\r\n')[0];
43+
const status = statusLine.split(' ')[1];
44+
assert.strictEqual(status, '404');
45+
client.end();
46+
}
47+
});
48+
client.on('end', common.mustCall());
49+
});
50+
});

0 commit comments

Comments
 (0)