]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
PR27531: retry within default retry_limit will be supported.
authorAlice Zhang <alizhang@redhat.com>
Tue, 6 Jul 2021 20:12:43 +0000 (16:12 -0400)
committerMark Wielaard <mark@klomp.org>
Fri, 9 Jul 2021 10:22:05 +0000 (12:22 +0200)
In debuginfod-client.c (debuginfod_query_server),insert a
goto statement for jumping back to the beginning of curl
handles set up if query fails and a non ENOENT error is returned.

Also introduced DEBUGINFOD_RETRY_LIMIT_ENV_VAR and default
DEBUGINFOD_RETRY_LIMIT(which is 2).

Correponding test has been added to tests/run-debuginfod-find.sh

Signed-off-by: Alice Zhang <alizhang@redhat.com>
config/ChangeLog
config/debuginfod.sysconfig
debuginfod/ChangeLog
debuginfod/debuginfod-client.c
debuginfod/debuginfod.h.in
doc/debuginfod_find_debuginfo.3
tests/ChangeLog
tests/run-debuginfod-find.sh

index 2cdcfa720599f83fd39e297fa5aa9ffcb148ea25..70a1e92391b9e85a8472fb57986188587a3f0c07 100644 (file)
@@ -1,3 +1,7 @@
+2021-07-06  Alice Zhang  <alizhang@redhat.com>
+
+        * debuginfod.sysconfig: Introduce default retry limit.
+
 2021-05-10  Mark Wielaard  <mark@klomp.org>
 
        * elfutils.spec.in: Update for 0.185.
index 446038742baec6f999e482ab1a757ceef79ef29e..890a1a25062eb19d3a078f8e3bdfef8f13687786 100644 (file)
@@ -11,4 +11,5 @@ DEBUGINFOD_PATHS="-t43200 -F -R /usr/lib/debug /usr/bin /usr/libexec /usr/sbin /
 # upstream debuginfods
 #DEBUGINFOD_URLS="http://secondhost:8002 http://thirdhost:8002"
 #DEBUGINFOD_TIMEOUT="5"
+#DEBUGINFOD_RETRY_LIMIT="2"
 #DEBUGINFOD_CACHE_DIR=""
index a4f20a7882f86b66fd8f64565bc64d89363f553a..e71436ca6280e6a218937fb8e0577756ec5f2bfb 100644 (file)
@@ -1,3 +1,10 @@
+2021-07-06  Alice Zhang  <alizhang@redhat.com>
+
+        PR27531
+       * debuginfod-client.c (debuginfod_query_server): Retry failed queries
+       if error code is not ENOENT.
+       * debuginfod.h.in: Introduce DEBUGINFOD_RETRY_LIMIT_ENV_VAR.
+
 2021-07-01  Noah Sanci <nsanci@redhat.com>
 
        PR27711
index f417b40aef06b9e9a8da53cd96d751f94215fd5b..f12f609ce58cd37d1bf70406a257c4d395a623c7 100644 (file)
@@ -157,6 +157,8 @@ static const char url_delim_char = ' ';
 /* Timeout for debuginfods, in seconds (to get at least 100K). */
 static const long default_timeout = 90;
 
+/* Default retry count for download error. */
+static const long default_retry_limit = 2;
 
 /* Data associated with a particular CURL easy handle. Passed to
    the write callback.  */
@@ -770,9 +772,14 @@ debuginfod_query_server (debuginfod_client *c,
         && (i == 0 || server_urls[i - 1] == url_delim_char))
       num_urls++;
   
+  int retry_limit = default_retry_limit;
+  const char* retry_limit_envvar = getenv(DEBUGINFOD_RETRY_LIMIT_ENV_VAR);
+  if (retry_limit_envvar != NULL)
+    retry_limit = atoi (retry_limit_envvar);
+
   CURLM *curlm = c->server_mhandle;
   assert (curlm != NULL);
-  
+
   /* Tracks which handle should write to fd. Set to the first
      handle that is ready to write the target file to the cache.  */
   CURL *target_handle = NULL;
@@ -785,6 +792,10 @@ debuginfod_query_server (debuginfod_client *c,
 
   /* thereafter, goto out1 on error.  */
 
+ /*The beginning of goto block query_in_parallel.*/
+ query_in_parallel:
+  rc = -ENOENT; /* Reset rc to default.*/
+
   /* Initialize handle_data with default values. */
   for (int i = 0; i < num_urls; i++)
     {
@@ -1074,8 +1085,27 @@ debuginfod_query_server (debuginfod_client *c,
         close(efd);
     }
 
+  /* If the verified_handle is NULL and rc != -ENOENT, the query fails with
+   * an error code other than 404, then do several retry within the retry_limit.
+   * Clean up all old handles and jump back to the beginning of query_in_parallel,
+   * reinitialize handles and query again.*/
   if (verified_handle == NULL)
-    goto out1;
+    {
+      if (rc != -ENOENT && retry_limit-- > 0)
+        {
+         if (vfd >= 0)
+            dprintf (vfd, "Retry failed query, %d attempt(s) remaining\n", retry_limit);
+         /* remove all handles from multi */
+          for (int i = 0; i < num_urls; i++)
+            {
+              curl_multi_remove_handle(curlm, data[i].handle); /* ok to repeat */
+              curl_easy_cleanup (data[i].handle);
+            }
+           goto query_in_parallel;
+       }
+      else
+       goto out1;
+    }
 
   if (vfd >= 0)
     {
index 559ea9479349e3e923262ef4427734d9f3bec49e..282e523db278c233843df96eec39c68d5b4e8d65 100644 (file)
@@ -35,6 +35,7 @@
 #define DEBUGINFOD_TIMEOUT_ENV_VAR "DEBUGINFOD_TIMEOUT"
 #define DEBUGINFOD_PROGRESS_ENV_VAR "DEBUGINFOD_PROGRESS"
 #define DEBUGINFOD_VERBOSE_ENV_VAR "DEBUGINFOD_VERBOSE"
+#define DEBUGINFOD_RETRY_LIMIT_ENV_VAR "DEBUGINFOD_RETRY_LIMIT"
 
 /* The libdebuginfod soname.  */
 #define DEBUGINFOD_SONAME "@LIBDEBUGINFOD_SONAME@"
index 5ae44a9834be56e87b2a294b1cb647e602da78c7..7730dd321035a29be4907944492a65948867bc15 100644 (file)
@@ -277,6 +277,11 @@ program is reexecuted. If XDG_CACHE_HOME is set then
 $XDG_CACHE_HOME/debuginfod_client is the default location, otherwise
 $HOME/.cache/debuginfod_client is used.
 
+.TP 21
+.B DEBUGINFOD_RETRY_LITMIT
+This environment variable governs the default limit of retry attempts. If a
+query failed with errno other than ENOENT, will initiate several attempts
+within the limit.
 
 .SH "ERRORS"
 The following list is not comprehensive. Error codes may also
index 3a30e06b5183fc8fa4fff67de6d25920b596ac41..1460b42226b2ea429e3be860056953f84e9521d8 100644 (file)
@@ -1,3 +1,8 @@
+2021-07-06  Alice Zhang  <alizhang@redhat.com>
+
+        PR27531
+       * run-debuginfod-find.sh: Add test case for retry mechanism.
+
 2021-07-01  Noah Sanci <nsanci@redhat.com>
 
        PR2711
index a4c1a13a8153b85d47bea1a84e5c56331c76cbcb..73bbe65b97824feb684917aacec5fe5c064f1480 100755 (executable)
@@ -620,6 +620,7 @@ curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_after_you.*'
 
 ########################################################################
 # Corrupt the sqlite database and get debuginfod to trip across its errors
+
 curl -s http://127.0.0.1:$PORT1/metrics | grep 'sqlite3.*reset'
 ls -al $DB
 dd if=/dev/zero of=$DB bs=1 count=1
@@ -737,4 +738,15 @@ wait_ready $PORT3 'groom{statistic="files scanned (#)"}' 0
 wait_ready $PORT3 'groom{statistic="files scanned (mb)"}' 0
 
 kill $PID4
-exit 0;
+
+########################################################################
+# set up tests for retrying failed queries.
+retry_attempts=`(testrun env DEBUGINFOD_URLS=http://255.255.255.255/JUNKJUNK DEBUGINFOD_RETRY_LIMIT=10 DEBUGINFOD_VERBOSE=1 \
+       ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo /bin/ls || true) 2>&1 >/dev/null \
+       | grep -c 'Retry failed query'`
+if [ $retry_attempts -ne 10 ]; then
+    echo "retry mechanism failed."
+    exit 1;
+  fi
+
+exit 0