mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 14:56:19 +00:00

`request.setTimeout()` calls `socket.setTimeout()` as soon as a socket is assigned to the request. This makes the `timeout` event to be emitted on the request even if the underlying socket never connects. This commit makes `socket.setTimeout()` to be called only when the underlying socket is connected. PR-URL: https://github.com/nodejs/node/pull/8895 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
27 lines
813 B
JavaScript
27 lines
813 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
|
|
const server = http.createServer((req, res) => {
|
|
// This space is intentionally left blank.
|
|
});
|
|
|
|
server.listen(0, common.localhostIPv4, common.mustCall(() => {
|
|
const port = server.address().port;
|
|
const req = http.get(`http://${common.localhostIPv4}:${port}`);
|
|
|
|
req.setTimeout(1);
|
|
req.on('socket', common.mustCall((socket) => {
|
|
assert.strictEqual(socket._idleTimeout, undefined);
|
|
socket.on('connect', common.mustCall(() => {
|
|
assert.strictEqual(socket._idleTimeout, 1);
|
|
}));
|
|
}));
|
|
req.on('timeout', common.mustCall(() => req.abort()));
|
|
req.on('error', common.mustCall((err) => {
|
|
assert.strictEqual('socket hang up', err.message);
|
|
server.close();
|
|
}));
|
|
}));
|