]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: checks: prevent http keep-alive with http-check expect
authorCyril Bonté <cyril.bonte@free.fr>
Thu, 29 Jan 2015 23:07:07 +0000 (00:07 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 29 Jan 2015 23:43:34 +0000 (00:43 +0100)
Sébastien Rohaut reported that string negation in http-check expect didn't
work as expected.

The misbehaviour is caused by responses with HTTP keep-alive. When the
condition is not met, haproxy awaits more data until the buffer is full or the
connection is closed, resulting in a check timeout when "timeout check" is
lower than the keep-alive timeout on the server side.

In order to avoid the issue, when a "http-check expect" is used, haproxy will
ask the server to disable keep-alive by automatically appending a
"Connection: close" header to the request.

doc/configuration.txt
src/checks.c

index 128447dc0a6b8b8a30c759b669e766ce8454786c..c8295905360a3acdcb5777f8b1e6a2b8dc72966a 100644 (file)
@@ -2905,6 +2905,10 @@ http-check expect [!] <match> <pattern>
   waste some CPU cycles, especially when regular expressions are used, and that
   it is always better to focus the checks on smaller resources.
 
+  Also "http-check expect" doesn't support HTTP keep-alive. Keep in mind that it
+  will automatically append a "Connection: close" header, meaning that this
+  header should not be present in the request provided by "option httpchk".
+
   Last, if "http-check expect" is combined with "http-check disable-on-404",
   then this last one has precedence when the server responds with 404.
 
index feca96e2f867c7813d475d23303d1bc54dcd3eb5..1b5b7319bd4daa6b8a93eccb11717aa5dd4172b1 100644 (file)
@@ -1427,6 +1427,9 @@ static int connect_conn_chk(struct task *t)
                else if ((check->type) == PR_O2_HTTP_CHK) {
                        if (s->proxy->options2 & PR_O2_CHK_SNDST)
                                bo_putblk(check->bo, trash.str, httpchk_build_status_header(s, trash.str, trash.size));
+                       /* prevent HTTP keep-alive when "http-check expect" is used */
+                       if (s->proxy->options2 & PR_O2_EXP_TYPE)
+                               bo_putstr(check->bo, "Connection: close\r\n");
                        bo_putstr(check->bo, "\r\n");
                        *check->bo->p = '\0'; /* to make gdb output easier to read */
                }