Commit Graph

4 Commits

Author SHA1 Message Date
Robert Nagy
8700d89306 http: fix socket re-use races
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>
2020-03-07 20:51:12 +01:00
Luigi Pinca
b8d9d4ac68 test: refactor test-http-agent-timeout-option
There is no need to establish a TCP connection. It is sufficient to
test that the listener that forwards the `'timeout'` event from the
socket to the `ClientRequest` instance is added to the socket.

PR-URL: https://github.com/nodejs/node/pull/25886
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2019-02-07 07:38:48 +01:00
Luigi Pinca
988482e234 test: refactor test-http-agent-timeout-option
Fix flakyness caused by usage of a non-routable IP address.

Refs: https://github.com/nodejs/node/pull/25488#issuecomment-459385146

PR-URL: https://github.com/nodejs/node/pull/25854
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2019-02-01 22:44:33 -08:00
Luigi Pinca
4b6e4c1eb1 http: make timeout event work with agent timeout
The `'timeout'` event is currently not emitted on the `ClientRequest`
instance when the socket timeout expires if only the `timeout` option
of the agent is set. This happens because, under these circumstances,
`listenSocketTimeout()` is not called.

This commit fixes the issue by calling it also when only the agent
`timeout` option is set.

PR-URL: https://github.com/nodejs/node/pull/25488
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-01-31 11:51:25 +01:00