Re: Fix potential hang in https handshake.
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:55:04
Jeff King [off-list ref] writes:
On Fri, Oct 19, 2012 at 07:10:46AM -0700, Shawn O. Pearce wrote:quoted
quoted
IOW, it seems like we are _already_ following the advice referenced in curl's manpage. Is there some case I am missing? Confused...The issue with the current code is sometimes when libcurl is opening a CONNECT style connection through an HTTP proxy it returns a crazy high timeout (>240 seconds) and no fds. In this case Git waits forever. Stefan observed that using a timeout of 50 ms in this situation to poll libcurl is better, as it figures out a lot more quickly that it is connected to the proxy and can issue the request.Ah. That sounds like a bug in curl to me. But either way, if we want to work around it, wouldn't the right thing be to override curl's timeout in that instance? Like:
Yeah, that sounds like a more targetted workaround (read: better).
quoted hunk
diff --git a/http.c b/http.c index df9bb71..cd07cdf 100644 --- a/http.c +++ b/http.c@@ -631,6 +631,19 @@ void run_active_slot(struct active_request_slot *slot) FD_ZERO(&excfds); curl_multi_fdset(curlm, &readfds, &writefds, &excfds, &max_fd); + /* + * Sometimes curl will give a really long timeout for a + * CONNECT when there are no fds to read, but we can + * get better results by running curl_multi_perform + * more frequently. + */ + if (maxfd < 0 && + (select_timeout.tv_sec > 0 || + select_timeout.tv_usec > 50000)) { + select_timeout.tv_sec = 0; + select_timeout.tv_usec = 50000; + } + select(max_fd+1, &readfds, &writefds, &excfds, &select_timeout); } } -Peff