-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: fix incorrect headersTimeout measurement
For keep-alive connections, the headersTimeout may fire during subsequent request because the measurement was reset after a request and not before a request. PR-URL: #32329 Fixes: #27363 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
Showing
6 changed files
with
104 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test/parallel/test-http-slow-headers-keepalive-multiple-requests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
const { finished } = require('stream'); | ||
|
||
const headers = | ||
'GET / HTTP/1.1\r\n' + | ||
'Host: localhost\r\n' + | ||
'Connection: keep-alive\r\n' + | ||
'Agent: node\r\n'; | ||
|
||
const baseTimeout = 1000; | ||
|
||
const server = http.createServer(common.mustCall((req, res) => { | ||
req.resume(); | ||
res.writeHead(200); | ||
res.end(); | ||
}, 2)); | ||
|
||
server.keepAliveTimeout = 10 * baseTimeout; | ||
server.headersTimeout = baseTimeout; | ||
|
||
server.once('timeout', common.mustNotCall((socket) => { | ||
socket.destroy(); | ||
})); | ||
|
||
server.listen(0, () => { | ||
const client = net.connect(server.address().port); | ||
|
||
// first request | ||
client.write(headers); | ||
client.write('\r\n'); | ||
|
||
setTimeout(() => { | ||
// second request | ||
client.write(headers); | ||
// `headersTimeout` doesn't seem to fire if request | ||
// is sent altogether. | ||
setTimeout(() => { | ||
client.write('\r\n'); | ||
client.end(); | ||
}, 10); | ||
}, baseTimeout + 10); | ||
|
||
client.resume(); | ||
finished(client, common.mustCall((err) => { | ||
server.close(); | ||
})); | ||
}); |