mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 14:25:18 +00:00

Whether and when a socket is destroyed or not after a timeout is up to the user. This leaves an edge case where a socket that has emitted 'timeout' might be re-used from the free pool. Even if destroy is called on the socket, it won't be removed from the freelist until 'close' which can happen several ticks later. Sockets are removed from the free list on the 'close' event. However, there is a delay between calling destroy() and 'close' being emitted. This means that it possible for a socket that has been destroyed to be re-used from the free list, causing unexpected failures. PR-URL: https://github.com/nodejs/node/pull/32000 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
24 lines
633 B
JavaScript
24 lines
633 B
JavaScript
'use strict';
|
|
|
|
const { mustCall } = require('../common');
|
|
const { strictEqual } = require('assert');
|
|
const { Agent, get } = require('http');
|
|
|
|
// Test that the listener that forwards the `'timeout'` event from the socket to
|
|
// the `ClientRequest` instance is added to the socket when the `timeout` option
|
|
// of the `Agent` is set.
|
|
|
|
const request = get({
|
|
agent: new Agent({ timeout: 50 }),
|
|
lookup: () => {}
|
|
});
|
|
|
|
request.on('socket', mustCall((socket) => {
|
|
strictEqual(socket.timeout, 50);
|
|
|
|
const listeners = socket.listeners('timeout');
|
|
|
|
strictEqual(listeners.length, 2);
|
|
strictEqual(listeners[1], request.timeoutCb);
|
|
}));
|