Skip to content

Commit

Permalink
Merge branch 'sz/maint-curl-multi-timeout' into maint
Browse files Browse the repository at this point in the history
Sometimes curl_multi_timeout() function suggested a wrong timeout
value when there is no file descriptors to wait on and the http
transport ended up sleeping for minutes in select(2) system call.  A
workaround has been added for this.

* sz/maint-curl-multi-timeout:
  Fix potential hang in https handshake
  • Loading branch information
Junio C Hamano committed Nov 19, 2012
2 parents b98769e + 7202b81 commit 8b56a47
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,18 @@ void run_active_slot(struct active_request_slot *slot)
FD_ZERO(&excfds);
curl_multi_fdset(curlm, &readfds, &writefds, &excfds, &max_fd);

/*
* It can happen that curl_multi_timeout returns a pathologically
* long timeout when curl_multi_fdset returns no file descriptors
* to read. See commit message for more details.
*/
if (max_fd < 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);
}
}
Expand Down

0 comments on commit 8b56a47

Please sign in to comment.