summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Sheplyakov <asheplyakov@altlinux.org>2021-08-30 13:58:38 +0400
committerAlexey Sheplyakov <asheplyakov@altlinux.org>2021-08-30 14:56:33 +0400
commita59c8a58caa912e85867749cbd03861f4654acc1 (patch)
tree501385da5771bab16b8c26e85d4e319ee5c779c8
parentfd6f688120e4f18decee6a49120837f27df53b35 (diff)
downloaddistcc-git-a59c8a58caa912e85867749cbd03861f4654acc1.tar.gz
Restrict the number of retries when DISTCC_BACKOFF is disabled
Since the commit a7dd5cf90e8c ("Try a new host after failing to connect instead of immediately falling back to localhost") distcc tries to choose a different host on connection/protocol errors. However when backoff is disabled (DISTCC_BACKOFF_PERIOD=0) distcc keeps retrying forever. To avoid the problem limit the number of retries (currently to 3) when backoff is disabled. Closes: #434
-rw-r--r--src/compile.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/compile.c b/src/compile.c
index 26d7d18..1fdee42 100644
--- a/src/compile.c
+++ b/src/compile.c
@@ -631,6 +631,18 @@ static int dcc_gcc_rewrite_fqn(char **argv)
return -ENOENT;
}
+static int dcc_get_max_retries(void)
+{
+ if (dcc_backoff_is_enabled()) {
+ /* eventually distcc will either find a suitable host or mark
+ * all hosts as faulty (and fallback to a local compilation)
+ */
+ return 0; /* no limit */
+ } else {
+ return 3; /* somewhat arbitrary */
+ }
+}
+
/**
* Execute the commands in argv remotely or locally as appropriate.
*
@@ -687,10 +699,13 @@ dcc_build_somewhere(char *argv[],
int cpu_lock_fd = -1, local_cpu_lock_fd = -1;
int ret;
int remote_ret = 0;
+ int retry_count = 0, max_retries;
struct dcc_hostdef *host = NULL;
char *discrepancy_filename = NULL;
char **new_argv;
+ max_retries = dcc_get_max_retries();
+
if ((ret = dcc_expand_preprocessor_options(&argv)) != 0)
goto clean_up;
@@ -841,7 +856,14 @@ dcc_build_somewhere(char *argv[],
/* dcc_compile_remote() already unlocked local_cpu_lock_fd. */
local_cpu_lock_fd = -1;
bad_host(host, &cpu_lock_fd, &local_cpu_lock_fd);
- goto choose_host;
+ retry_count++;
+ if (max_retries == 0 || retry_count < max_retries)
+ goto choose_host;
+ else {
+ rs_log_warning("Couldn't find a host in %d attempts, retrying locally",
+ retry_count);
+ goto fallback;
+ }
}
/* dcc_compile_remote() already unlocked local_cpu_lock_fd. */
local_cpu_lock_fd = -1;