Socket descriptor is not closed if connection times out
Closed this issue · 4 comments
In TCPConnector::connect()
line 122, socket descriptor is not closed leading to resource leak. This issue may be related to #1.
No, the socket is connected at this point and will be transferred to a TCPStream object that will ultimately close the connection.
Hi, sorry to be pressing the point: I probably did not completely describe the issue, or I'm missing something.
Assume connect times out in TCPConnector::connect(server, port, timeout)
: result
remains set to -1
, an error message is printed, and NULL
is returned. However the socket descriptor sd
is not closed. If the program keeps running and the server comes online, you will receive a new connection on the server side but obviously no messages are exchanged.
You can check this yourself using valgrind (trigger connection timeout):
valgrind --track-fds=yes ./client_timeout 81 81 www.google.com 2
Cheers
Ok I see. That's a good point. I'll fix the code then. Thanks for the analysis.
The socket is now closed when the connection times out.