]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: httpclient: allow to configure the retries
authorWilliam Lallemand <wlallemand@haproxy.org>
Tue, 5 Sep 2023 13:55:04 +0000 (15:55 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Tue, 5 Sep 2023 13:55:04 +0000 (15:55 +0200)
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
src/http_client.c

index 245316060bf5463983bd6ef000f4b75bc71e5b15..982bc6ae52dd12943c2787d4bd503291d371b990 100644 (file)
@@ -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 <ipv4|ipv6>
   which is convenient when IPv6 is not available on your network. Default
   option is "ipv6".
 
+httpclient.retries <number>
+  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 <cafile>
   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
index 46cdbdb5d58afbeb0359581e5e6701619af4d3e5..cc9a1b0126415b30df2291712e8eda88f73df764 100644 (file)
@@ -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 },