{"thread":{"id":"31872","subject":"[PATCH] Fix potential hang in https handshake.","startedAt":"2012-10-19T21:39:34Z","lastAt":"2012-10-19T21:49:04Z","messageCount":2,"participants":["szager@google.com","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"201576","messageId":"5081c896.cMdU6VySSwFm0uOa%szager@google.com","threadId":"31872","inReplyTo":null,"subject":"[PATCH] Fix potential hang in https handshake.","fromName":"","fromEmail":"szager@google.com","sentAt":"2012-10-19T21:39:34Z","receivedAt":"2012-10-19T21:39:34Z","isPatch":true,"sender":{"key":"szager@google.com","avatar":null},"body":"It has been observed that curl_multi_timeout may return a very long\ntimeout value (e.g., 294 seconds and some usec) just before\ncurl_multi_fdset returns no file descriptors for reading.  The\nupshot is that select() will hang for a long time -- long enough for\nan https handshake to be dropped.  The observed behavior is that\nthe git command will hang at the terminal and never transfer any\ndata.\n\nThis patch is a workaround for a probable bug in libcurl.  The bug\nonly seems to manifest around a very specific set of circumstances:\n\n- curl version (from curl/curlver.h):\n\n #define LIBCURL_VERSION_NUM 0x071307\n\n- git-remote-https running on an ubuntu-lucid VM.\n- Connecting through squid proxy running on another VM.\n\nInterestingly, the problem doesn't manifest if a host connects\nthrough squid proxy running on localhost; only if the proxy is on\na separate VM (not sure if the squid host needs to be on a separate\nphysical machine).  That would seem to suggest that this issue\nis timing-sensitive.\n\nThis patch is more or less in line with a recommendation in the\ncurl docs about how to behave when curl_multi_fdset doesn't return\nand file descriptors:\n\nhttp://curl.haxx.se/libcurl/c/curl_multi_fdset.html\n\nSigned-off-by: Stefan Zager <szager@google.com>\n---\n http.c |   12 ++++++++++++\n 1 files changed, 12 insertions(+), 0 deletions(-)\n\ndiff --git a/http.c b/http.c\nindex df9bb71..b7e7ab4 100644\n--- a/http.c\n+++ b/http.c\n@@ -631,6 +631,18 @@ void run_active_slot(struct active_request_slot *slot)\n \t\t\tFD_ZERO(&excfds);\n \t\t\tcurl_multi_fdset(curlm, &readfds, &writefds, &excfds, &max_fd);\n \n+\t\t\t/*\n+\t\t\t * It can happen that curl_multi_timeout returns a pathologically\n+\t\t\t * long timeout when curl_multi_fdset returns no file descriptors\n+\t\t\t * to read.  See commit message for more details.\n+\t\t\t */\n+\t\t\tif (max_fd < 0 &&\n+\t\t\t    (select_timeout.tv_sec > 0 ||\n+                             select_timeout.tv_usec > 50000)) {\n+                        \tselect_timeout.tv_sec  = 0;\n+                                select_timeout.tv_usec = 50000;\n+\t\t\t}\n+\n \t\t\tselect(max_fd+1, &readfds, &writefds, &excfds, &select_timeout);\n \t\t}\n \t}\n-- \n1.7.7.3\n"},{"id":"201577","messageId":"7vehkui14f.fsf@alter.siamese.dyndns.org","threadId":"31872","inReplyTo":"5081c896.cMdU6VySSwFm0uOa%szager@google.com","subject":"Re: [PATCH] Fix potential hang in https handshake.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-10-19T21:49:04Z","receivedAt":"2012-10-19T21:49:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}