MINOR: checks: add min-recv tcp-check expect option
Some expect rules cannot be satisfied due to inherent ambiguity towards
the received data: in the absence of match, the current behavior is to
be forced to wait either the end of the connection or a buffer full,
whichever comes first. Only then does the matching diagnostic is
considered conclusive. For instance :
tcp-check connect
tcp-check expect !rstring "^error"
tcp-check expect string "valid"
This check will only succeed if the connection is closed by the server before
the check timeout. Otherwise the first expect rule will wait for more data until
"^error" regex matches or the check expires.
Allow the user to explicitly define an amount of data that will be
considered enough to determine the value of the check.
This allows succeeding on negative rstring rules, as previously
in valid condition no match happened, and the matching was repeated
until the end of the connection. This could timeout the check
while no error was happening.
[Cf: I slighly updated the patch. The parameter was renamed and the value is a
signed integer to support -1 as default value to ignore the parameter.]
diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
index 911255b..4b099c1 100644
--- a/src/cfgparse-listen.c
+++ b/src/cfgparse-listen.c
@@ -3192,6 +3192,7 @@
}
else if (strcmp(args[1], "expect") == 0) {
struct tcpcheck_rule *tcpcheck, *prev_check;
+ long min_recv = -1;
const char *ptr_arg;
int cur_arg;
int inverse = 0;
@@ -3203,6 +3204,30 @@
}
cur_arg = 2;
+
+ /* Parse potential the minimum amount of data
+ * required before proceeding with the match.
+ */
+ if (strcmp(args[cur_arg], "min-recv") == 0) {
+ if (!*(args[cur_arg + 1])) {
+ ha_alert("parsing [%s:%d] : '%s %s %s' expects an integer as an argument.\n",
+ file, linenum, args[0], args[1], args[2]);
+ err_code |= ERR_ALERT | ERR_FATAL;
+ goto out;
+ }
+
+ /* Use an signed integer here because of chksize */
+ min_recv = atol(args[cur_arg + 1]);
+ if (min_recv < -1 || min_recv > INT_MAX) {
+ ha_alert("parsing [%s:%d] : '%s %s %s' expects -1 or an integer from 0 to INT_MAX.\n",
+ file, linenum, args[0], args[1], args[2]);
+ err_code |= ERR_ALERT | ERR_FATAL;
+ goto out;
+ }
+
+ cur_arg += 2;
+ }
+
/* consider exclamation marks, sole or at the beginning of a word */
while (*(ptr_arg = args[cur_arg])) {
while (*ptr_arg == '!') {
@@ -3221,6 +3246,7 @@
tcpcheck = calloc(1, sizeof(*tcpcheck));
tcpcheck->action = TCPCHK_ACT_EXPECT;
tcpcheck->inverse = inverse;
+ tcpcheck->min_recv = min_recv;
if (strcmp(ptr_arg, "binary") == 0) {
char *err = NULL;