[curl/f19] avoid a busy-loop in curl_easy_perform()
Kamil Dudka
kdudka at fedoraproject.org
Wed Sep 4 16:49:26 UTC 2013
commit 68cb5f29336af9dcee4fff3835305b867e20d78e
Author: Kamil Dudka <kdudka at redhat.com>
Date: Wed Sep 4 18:41:43 2013 +0200
avoid a busy-loop in curl_easy_perform()
0011-curl-7.29.0-0feeab78.patch | 74 +++++++++++++++++++++++++++++++++++++++
curl.spec | 9 ++++-
2 files changed, 82 insertions(+), 1 deletions(-)
---
diff --git a/0011-curl-7.29.0-0feeab78.patch b/0011-curl-7.29.0-0feeab78.patch
new file mode 100644
index 0000000..bd6b8b3
--- /dev/null
+++ b/0011-curl-7.29.0-0feeab78.patch
@@ -0,0 +1,74 @@
+From d3036f34cce421990e8268ee4bbfc0d9f5ceb054 Mon Sep 17 00:00:00 2001
+From: Daniel Stenberg <daniel at haxx.se>
+Date: Thu, 13 Jun 2013 19:27:12 +0200
+Subject: [PATCH] curl_easy_perform: avoid busy-looping
+
+When curl_multi_wait() finds no file descriptor to wait for, it returns
+instantly and this must be handled gracefully within curl_easy_perform()
+or cause a busy-loop. Starting now, repeated fast returns without any
+file descriptors is detected and a gradually increasing sleep will be
+used (up to a max of 1000 milliseconds) before continuing the loop.
+
+Bug: http://curl.haxx.se/bug/view.cgi?id=1238
+Reported-by: Miguel Angel
+
+[upstream commit 0feeab7802dd2a6465d22d153d8d36b2cca99b96]
+
+Signed-off-by: Kamil Dudka <kdudka at redhat.com>
+---
+ lib/easy.c | 25 +++++++++++++++++++++++++
+ 1 files changed, 25 insertions(+), 0 deletions(-)
+
+diff --git a/lib/easy.c b/lib/easy.c
+index 2739598..a7051dd 100644
+--- a/lib/easy.c
++++ b/lib/easy.c
+@@ -410,6 +410,9 @@ CURLcode curl_easy_perform(CURL *easy)
+ bool done = FALSE;
+ int rc;
+ struct SessionHandle *data = easy;
++ int without_fds = 0; /* count number of consecutive returns from
++ curl_multi_wait() without any filedescriptors */
++ struct timeval before;
+
+ if(!easy)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+@@ -445,6 +448,7 @@ CURLcode curl_easy_perform(CURL *easy)
+ int still_running;
+ int ret;
+
++ before = curlx_tvnow();
+ mcode = curl_multi_wait(multi, NULL, 0, 1000, &ret);
+
+ if(mcode == CURLM_OK) {
+@@ -453,6 +457,27 @@ CURLcode curl_easy_perform(CURL *easy)
+ code = CURLE_RECV_ERROR;
+ break;
+ }
++ else if(ret == 0) {
++ struct timeval after = curlx_tvnow();
++ /* If it returns without any filedescriptor instantly, we need to
++ avoid busy-looping during periods where it has nothing particular
++ to wait for */
++ if(curlx_tvdiff(after, before) <= 10) {
++ without_fds++;
++ if(without_fds > 2) {
++ int sleep_ms = without_fds * 50;
++ if(sleep_ms > 1000)
++ sleep_ms = 1000;
++ Curl_wait_ms(sleep_ms);
++ }
++ }
++ else
++ /* it wasn't "instant", restart counter */
++ without_fds = 0;
++ }
++ else
++ /* got file descriptor, restart counter */
++ without_fds = 0;
+
+ mcode = curl_multi_perform(multi, &still_running);
+ }
+--
+1.7.1
+
diff --git a/curl.spec b/curl.spec
index 34e6562..506a0ca 100644
--- a/curl.spec
+++ b/curl.spec
@@ -1,7 +1,7 @@
Summary: A utility for getting files from remote servers (FTP, HTTP, and others)
Name: curl
Version: 7.29.0
-Release: 9%{?dist}
+Release: 10%{?dist}
License: MIT
Group: Applications/Internet
Source: http://curl.haxx.se/download/%{name}-%{version}.tar.lzma
@@ -37,6 +37,9 @@ Patch9: 0009-curl-7.29.0-3a0e931f.patch
# FTP: when EPSV gets a 229 but fails to connect, retry with PASV (#1002815)
Patch10: 0010-curl-7.29.0-7cc00d9a.patch
+# avoid a busy-loop in curl_easy_perform()
+Patch11: 0011-curl-7.29.0-0feeab78.patch
+
# patch making libcurl multilib ready
Patch101: 0101-curl-7.29.0-multilib.patch
@@ -140,6 +143,7 @@ documentation of the library, too.
%patch8 -p1
%patch9 -p1
%patch10 -p1
+%patch11 -p1
# Fedora patches
%patch101 -p1
@@ -257,6 +261,9 @@ rm -rf $RPM_BUILD_ROOT
%{_datadir}/aclocal/libcurl.m4
%changelog
+* Wed Sep 04 2013 Kamil Dudka <kdudka at redaht.com> 7.29.0-10
+- avoid a busy-loop in curl_easy_perform()
+
* Fri Aug 30 2013 Kamil Dudka <kdudka at redaht.com> 7.29.0-9
- FTP: when EPSV gets a 229 but fails to connect, retry with PASV (#1002815)
More information about the scm-commits
mailing list