mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
http: make ClientRequest#setTimeout() noop at end
Originally discovered and resolved by @szmarczak. PR-URL: https://github.com/nodejs/node/pull/25536 Fixes: https://github.com/nodejs/node/issues/25499 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
f8800c90b1
commit
ced7f67fbb
2 files changed
+37
No files matched your search
@@ -727,6 +727,10 @@ function _deferToConnect(method, arguments_, cb) {
|
||||
}
|
||||
|
||||
ClientRequest.prototype.setTimeout = function setTimeout(msecs, callback) {
|
||||
if (this._ended) {
|
||||
return this;
|
||||
}
|
||||
|
||||
listenSocketTimeout(this);
|
||||
msecs = validateTimerDuration(msecs);
|
||||
if (callback) this.once('timeout', callback);
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
// Test https://github.com/nodejs/node/issues/25499 fix.
|
||||
|
||||
const { mustCall } = require('../common');
|
||||
|
||||
const { Agent, createServer, get } = require('http');
|
||||
const { strictEqual } = require('assert');
|
||||
|
||||
const server = createServer(mustCall((req, res) => {
|
||||
res.end();
|
||||
}));
|
||||
|
||||
server.listen(0, () => {
|
||||
const agent = new Agent({ keepAlive: true, maxSockets: 1 });
|
||||
const port = server.address().port;
|
||||
|
||||
let socket;
|
||||
|
||||
const req = get({ agent, port }, (res) => {
|
||||
res.on('end', () => {
|
||||
strictEqual(req.setTimeout(0), req);
|
||||
strictEqual(socket.listenerCount('timeout'), 0);
|
||||
agent.destroy();
|
||||
server.close();
|
||||
});
|
||||
res.resume();
|
||||
});
|
||||
|
||||
req.on('socket', (sock) => {
|
||||
socket = sock;
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user