cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-tracker mailing list Archives

[ curl-Bugs-3017819 ] trynextip() doesn't work with multi_socket_action and kqueue

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Thu, 17 Jun 2010 23:15:39 +0000

Bugs item #3017819, was opened at 2010-06-17 23:15
Message generated for change (Tracker Item Submitted) made by
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=3017819&group_id=976

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: libcurl
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Ben Darnell ()
Assigned to: Daniel Stenberg (bagder)
Summary: trynextip() doesn't work with multi_socket_action and kqueue

Initial Comment:
When a hostname resolves to multiple IP addresses and the first one tried doesn't work, the socket for the second attempt may get dropped on the floor, causing the request to eventually time out. The issue is that when using kqueue (as on mac and bsd platforms) instead of select, the kernel removes the first fd from kqueue when it is closed (in trynextip, connect.c:503). Trynextip() then goes on to open a new socket, which gets assigned the same number as the one it just closed. Later in multi.c, socket_cb is not called because the fd is already in multi->sockhash, so the new socket is never added to kqueue.

The correct fix is to ensure that socket_cb is called to remove the fd when trynextip() closes the socket, and again to re-add it after singleipsocket(). I'm not sure how to cleanly do that, but the attached patch works around the problem in an admittedly kludgy way by delaying the close to ensure that the newly-opened socket gets a different fd.

I have verified that the problem exists in libcurl 7.20.0 and 7.21.0 on Mac OS 10.6. I cannot reproduce the problem in libcurl 7.19.7, although the difference appears to be because that version tries the available IP addresses in a different order than the later releases, so the underlying problem is likely still present.

The problem does not occur when using select()/poll(), as those functions are not stateful and there is no magic causing the socket to be automatically forgotten when it is closed. I have not been able to reproduce the problem with epoll on linux, but my reading of the docs suggests that it may be a problem there as well.

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=3017819&group_id=976
Received on 2010-06-18

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET