Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#865 cannot connect to localhost on Mac OS

closed-fixed
libcurl (354)
5
2013-06-21
2009-09-29
Tom Mueller
No

Using libcURL with pycurl on Mac OS X 10.4, I'm seeing a problem with establishing a connection to a server running on localhost. This is a transient problem, with a failure occurring about 80-90% of the time.

After much digging, the root cause of the problem appears to be in the connect.c file, the trynextip function. This function is supposed to return TRUE if there are no more addresses to try or if there is an error. Presumably, if it can try the next IP address and there is no error, then it should return FALSE. However, this function always returns TRUE. If I change the "break" statement within this function to "return FALSE", then my program is able to connect successfully to localhost every time. I'm seeing this problem on version 7.19.5. I checked the trunk, and the break statement is still there so I'm assuming that this has not yet been fixed.

The test program is attempting to connect using multi mode with non-blocking sockets enabled. On Mac OS, localhost resolves first to an IPv6 address and then to the IPv4 address (127.0.0.1). The program first attempts to connect on IPv6. The initial connect call returns -1 with an in progress errno. Then a select call is made to see if the connect has completed. If the first select returns 1, then waitconnect determines that the IPv6 connection failed, the IPv4 connection is tried and the program works. However, if the first select returns 0, then going back to the main do loop which eventually calls Curl_is_connected, which finds out that the connection failed, so trynextip is called, which returns TRUE (meaning the connection failed) even though the connection really would have succeeded eventually. So the transient nature of this problem all depends on whether that first select on the IPv6 connection attempt returns 0 or 1.

Discussion

  • Thanks for the report, this problem is now fixed in CVS!

     
    • status: open --> closed-fixed