]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: backend: implement "http-reuse safe"
authorWilly Tarreau <w@1wt.eu>
Wed, 5 Aug 2015 14:02:46 +0000 (16:02 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 6 Aug 2015 09:50:53 +0000 (11:50 +0200)
The "safe" mode consists in picking existing connections only when
processing a request that's not the first one from a connection. This
ensures that in case where the server finally times out and closes, the
client can decide to replay idempotent requests.

src/backend.c
src/cfgparse.c

index 93eecbf0c7e1913537d07811de6420bfacdba361..18f688d1ebab838df1b1c0b342afcef98ae4cb56 100644 (file)
@@ -1046,8 +1046,9 @@ int connect_server(struct stream *s)
                         */
                }
 
-               if ((s->be->options & PR_O_REUSE_MASK) == PR_O_REUSE_ALWS &&
-                   !LIST_ISEMPTY(&srv->idle_conns)) {
+               if (((s->be->options & PR_O_REUSE_MASK) == PR_O_REUSE_ALWS ||
+                    ((s->be->options & PR_O_REUSE_MASK) == PR_O_REUSE_SAFE && s->txn && (s->txn->flags & TX_NOT_FIRST)))
+                   && !LIST_ISEMPTY(&srv->idle_conns)) {
                        /* We're going to have to pick the first connection
                         * from this pool and use it for our purposes. We may
                         * have to get rid of the current idle connection, so
index 9a2316fc0c9c5e2eddb06bb8e8af1385efdbe88f..9f7a6b53b3806ab3d62a1850af5f1e8264e71ddf 100644 (file)
@@ -5035,6 +5035,13 @@ stats_error_parsing:
                        if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
                                goto out;
                }
+               else if (strcmp(args[1], "safe") == 0) {
+                       /* enable a graceful server shutdown on an HTTP 404 response */
+                       curproxy->options &= ~PR_O_REUSE_MASK;
+                       curproxy->options |= PR_O_REUSE_SAFE;
+                       if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
+                               goto out;
+               }
                else if (strcmp(args[1], "always") == 0) {
                        /* enable a graceful server shutdown on an HTTP 404 response */
                        curproxy->options &= ~PR_O_REUSE_MASK;
@@ -5043,7 +5050,7 @@ stats_error_parsing:
                                goto out;
                }
                else {
-                       Alert("parsing [%s:%d] : '%s' only supports 'never', 'always'.\n", file, linenum, args[0]);
+                       Alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'always'.\n", file, linenum, args[0]);
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
                }