[PATCH] Cleanup dead connections in CLOSE_WAIT state sooner
Date: Mon, 2 Mar 2009 13:58:11 -0800
Currently, if you open a persistent connection to a backend server
using libcurl, the connection will be left open indefinitely. If the
server closes the connection due to inactivity, libcurl will only
notice this when you attempt to reuse the connection.
This behavior is documented in the curl issue tracker:
The big issue with curl's behavior is that it wastes connection
resources. Sockets sit around (practically forever) in CLOSE_WAIT. If
(for example) you don't need to reuse said connection, but instead
want to open a different connection to a different server, the dead
connection will still stick around forever. If, as a result, you run
out of file handles, you won't be able to open any more connections.
Fortunately, it is relatively easy to patch Curl to close dead
connections. The attached patch closes dead connections whenever you
attempt to open a new connection.
This patch makes two changes:
1. After cleaning up a dead connection, "continue" instead of
returning FALSE. This ensures that we clean up all dead connections,
rather than just cleaning up the first dead connection.
2. Move up the cleanup for dead connections so that it occurs for
all connections, rather than just the connections which have the same
preferences as our current new connection.
- text/plain attachment: curl-close-dead-connections-patch.txt