cURL / Mailing Lists / curl-library / Single Mail

curl-library

[PATCH] Cleanup dead connections in CLOSE_WAIT state sooner

From: David James <james82_at_gmail.com>
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:
  http://sourceforge.net/tracker/?func=detail&atid=100976&aid=1358860&group_id=976

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.

Thoughts?

Cheers,

David

Received on 2009-03-02