From c52948bd2cad65cdee62744d315686cfa317125f Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Tue, 5 Sep 2023 15:55:04 +0200 Subject: [PATCH] MINOR: httpclient: allow to configure the retries When using the httpclient, one could be bothered with it returning after a very long time when failing. By default the httpclient has a retries of 3 and a timeout connect of 5s, which can results in pause of 20s upon failure. This patch allows the user to configure the retries of the httpclient so it could reduce the time to return an error. This patch helps fixing part of the issue #2269. Could be backported in 2.7 if needed. --- doc/configuration.txt | 8 ++++++++ src/http_client.c | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 245316060..982bc6ae5 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -1088,6 +1088,7 @@ The following keywords are supported in the "global" section : - httpclient.resolvers.disabled - httpclient.resolvers.id - httpclient.resolvers.prefer + - httpclient.retries - httpclient.ssl.ca-file - httpclient.ssl.verify - insecure-fork-wanted @@ -1729,6 +1730,13 @@ httpclient.resolvers.prefer which is convenient when IPv6 is not available on your network. Default option is "ipv6". +httpclient.retries + This option allows to configure the number of retries attempt of the + httpclient when a request failed. This does the same as the "retries" keyword + in a backend. + + Default value is 3. + httpclient.ssl.ca-file This option defines the ca-file which should be used to verify the server certificate. It takes the same parameters as the "ca-file" option on the diff --git a/src/http_client.c b/src/http_client.c index 46cdbdb5d..cc9a1b012 100644 --- a/src/http_client.c +++ b/src/http_client.c @@ -55,6 +55,8 @@ static char *resolvers_id = NULL; static char *resolvers_prefer = NULL; static int resolvers_disabled = 0; +static int httpclient_retries = CONN_RETRIES; + /* --- This part of the file implement an HTTP client over the CLI --- * The functions will be starting by "hc_cli" for "httpclient cli" */ @@ -1218,7 +1220,7 @@ struct proxy *httpclient_create_proxy(const char *id) px->mode = PR_MODE_HTTP; px->maxconn = 0; px->accept = NULL; - px->conn_retries = CONN_RETRIES; + px->conn_retries = httpclient_retries; px->timeout.client = TICK_ETERNITY; /* The HTTP Client use the "option httplog" with the global log server */ px->conf.logformat_string = httpclient_log_format; @@ -1529,10 +1531,29 @@ static int httpclient_parse_global_verify(char **args, int section_type, struct } #endif /* ! USE_OPENSSL */ +static int httpclient_parse_global_retries(char **args, int section_type, struct proxy *curpx, + const struct proxy *defpx, const char *file, int line, + char **err) +{ + if (too_many_args(1, args, err, NULL)) + return -1; + + if (*(args[1]) == 0) { + ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", + file, line, args[0]); + return -1; + } + httpclient_retries = atol(args[1]); + + return 0; +} + + static struct cfg_kw_list cfg_kws = {ILH, { { CFG_GLOBAL, "httpclient.resolvers.disabled", httpclient_parse_global_resolvers_disabled }, { CFG_GLOBAL, "httpclient.resolvers.id", httpclient_parse_global_resolvers }, { CFG_GLOBAL, "httpclient.resolvers.prefer", httpclient_parse_global_prefer }, + { CFG_GLOBAL, "httpclient.retries", httpclient_parse_global_retries }, #ifdef USE_OPENSSL { CFG_GLOBAL, "httpclient.ssl.verify", httpclient_parse_global_verify }, { CFG_GLOBAL, "httpclient.ssl.ca-file", httpclient_parse_global_ca_file },