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-2784055 ] connect race with multi and socks proxy

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Mon, 04 May 2009 12:53:18 +0000

Bugs item #2784055, was opened at 2009-04-30 02:11
Message generated for change (Comment added) made by bagder
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=2784055&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: Constantine Sapuntzakis (csapuntz)
Assigned to: Daniel Stenberg (bagder)
Summary: connect race with multi and socks proxy

Initial Comment:
Symptom: connections through SOCKS proxy fail when using multi interface - especially SOCKS4A.

Problem: socket is being used by Curl_SOCKS4 before it is connected

Solution: block on connect

Seen on Windows.

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

>Comment By: Daniel Stenberg (bagder)
Date: 2009-05-04 14:53

Message:
Right, but my suggested approach is only a stop-gap take anyway, just less
crude than yours. See my uploaded patch attempt for an explanation on what
I mean.

This approach waits for the TCP connect to be verified before it calls the
socks-functions, and thus I hope it'll survive better.

What do you think about this?

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

Comment By: Constantine Sapuntzakis (csapuntz)
Date: 2009-05-02 00:43

Message:
Agree that not blocking would be the best solution but until that gets
written, I suggest this patch as a stopgap. Since many SOCKS proxies are in
the LAN i.e. low delay, blocking may not be that bad for the app. The
current behavior is bad.

Here are the states I see for SOCKS:
   - waiting for SOCKS connect
   - Send DNS request for final hostname (not 4a or 5_HOSTNAME)
   - waiting for DNS response
   - sending SOCKS request
   - waiting for SOCKS reply

I suppose those states can get assigned states at the top level state
machine or SOCKS could
maintain its own substate under CURLM_STATE_WAITCONNECT.

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

Comment By: Daniel Stenberg (bagder)
Date: 2009-05-01 22:26

Message:
sorry, it should be at the CURLM_STATE_WAITCONNECT position, which happens
at TCP connect

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

Comment By: Daniel Stenberg (bagder)
Date: 2009-05-01 22:13

Message:
Ah, yes thanks for clarifying!

But instead of taking the route of making the behavior even more blocking,
I would instead suggest that we make the socks proxy approach more similar
to the http proxy one.

It uses the asynch connection approch, so for the case when we use the
multi interface and Curl_connecthost() doesn't complete the connect, we
could instead make the socks negotiation magic get called when we reach the
CURLM_STATE_PROTOCONNECT state in lib/multi.c. Wouldn't that work (better)
you think?

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

Comment By: Constantine Sapuntzakis (csapuntz)
Date: 2009-04-30 15:02

Message:
Better description of problem: I was seeing 75% of my Socks4a connections
failing on setup with socket not connected. Now I see 0%.

The flow I was seeing (before the patch) is the following:

ConnectPlease calls Curl_connecthere which returns immediately in case of
curl_multi, not waiting for connet to finish

ConnectPlease calls Curl_SOCKS4
   which (in the case of SOCKS4a) calls Curl_write_plain
        which calls send() which gets back socket is not connected

The eventual solution is to make Curl_SOCKS support multi directly and not
require blocking, but that will take a lot more time. In the meantime,
there is bug on the known bugs list that says that curl blocks during proxy
connect and multi, but it actually doesn't on Windows.

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

Comment By: Daniel Stenberg (bagder)
Date: 2009-04-30 09:51

Message:
Your patch makes the connect phase blocking. I don't see why that is
necessary. libcurl should simply proceed as usual until connected, why is
using a (socks) proxy any different that any other proxy or connection?

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

Comment By: Constantine Sapuntzakis (csapuntz)
Date: 2009-04-30 02:12

Message:
See attached patch. Not all connections fail - some succeed.

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

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=2784055&group_id=976
Received on 2009-05-04

These mail archives are generated by hypermail.

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

File upload with ASP.NET