From: Willy Tarreau Date: Fri, 23 Nov 2012 13:02:10 +0000 (+0100) Subject: BUG/MINOR: checks: slightly clean the state machine up X-Git-Tag: v1.5-dev14~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=acbdc7a7603a0c1d55fd52e3d4f8390105849f9d;p=thirdparty%2Fhaproxy.git BUG/MINOR: checks: slightly clean the state machine up The process_chk() function still did not consider the the timeout when it was woken up, so a spurious wakeup could trigger a false timeout. Some checks were now redundant or could not be triggered (eg: L7 timeout). So remove them and rearrange the timeout detection. --- diff --git a/src/checks.c b/src/checks.c index 24e6cb07e7..2c5e2a9d48 100644 --- a/src/checks.c +++ b/src/checks.c @@ -1246,10 +1246,11 @@ static struct task *process_chk(struct task *t) struct connection *conn = s->check.conn; int rv; int ret; + int expired = tick_is_expired(t->expire, now_ms); if (!(s->state & SRV_CHK_RUNNING)) { /* no check currently running */ - if (!tick_is_expired(t->expire, now_ms)) /* woke up too early */ + if (!expired) /* woke up too early */ return t; /* we don't send any health-checks when the proxy is stopped or when @@ -1373,26 +1374,33 @@ static struct task *process_chk(struct task *t) * which can happen on connect timeout or error. */ if (s->result == SRV_CHK_UNKNOWN) { - if ((conn->flags & CO_FL_CONNECTED) && !(s->proxy->options2 & PR_O2_CHK_ANY)) { - /* good connection is enough for pure TCP check */ - if (s->check.use_ssl) - set_server_check_status(s, HCHK_STATUS_L6OK, NULL); - else - set_server_check_status(s, HCHK_STATUS_L4OK, NULL); - } - else if ((conn->flags & (CO_FL_CONNECTED|CO_FL_WAIT_L4_CONN)) == CO_FL_WAIT_L4_CONN) { - /* L4 failed */ + if ((conn->flags & (CO_FL_CONNECTED|CO_FL_WAIT_L4_CONN)) == CO_FL_WAIT_L4_CONN) { + /* L4 not established (yet) */ if (conn->flags & CO_FL_ERROR) set_server_check_status(s, HCHK_STATUS_L4CON, NULL); - else + else if (expired) set_server_check_status(s, HCHK_STATUS_L4TOUT, NULL); } else if ((conn->flags & (CO_FL_CONNECTED|CO_FL_WAIT_L6_CONN)) == CO_FL_WAIT_L6_CONN) { - /* L6 failed */ + /* L6 not established (yet) */ if (conn->flags & CO_FL_ERROR) set_server_check_status(s, HCHK_STATUS_L6RSP, NULL); + else if (expired) + set_server_check_status(s, HCHK_STATUS_L6TOUT, NULL); + } + else if ((conn->flags & CO_FL_CONNECTED) && !(s->proxy->options2 & PR_O2_CHK_ANY)) { + /* good connection is enough for pure TCP check */ + if (s->check.use_ssl) + set_server_check_status(s, HCHK_STATUS_L6OK, NULL); else + set_server_check_status(s, HCHK_STATUS_L4OK, NULL); + } + else if ((conn->flags & CO_FL_CONNECTED) && expired) { + /* connection established but expired check */ + if ((s->proxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) set_server_check_status(s, HCHK_STATUS_L6TOUT, NULL); + else /* HTTP, SMTP, ... */ + set_server_check_status(s, HCHK_STATUS_L7TOUT, NULL); } } @@ -1426,18 +1434,7 @@ static struct task *process_chk(struct task *t) } t->expire = tick_add(now_ms, MS_TO_TICKS(srv_getinter(s) + rv)); } - else if ((s->result & SRV_CHK_FAILED) || tick_is_expired(t->expire, now_ms)) { - if (!(s->result & SRV_CHK_FAILED)) { - if (conn->flags & CO_FL_WAIT_L4_CONN) { - set_server_check_status(s, HCHK_STATUS_L4TOUT, NULL); - } else { - if ((s->proxy->options2 & PR_O2_CHK_ANY) == PR_O2_SSL3_CHK) - set_server_check_status(s, HCHK_STATUS_L6TOUT, NULL); - else /* HTTP, SMTP */ - set_server_check_status(s, HCHK_STATUS_L7TOUT, NULL); - } - } - + else if (s->result & SRV_CHK_FAILED) { /* failure or timeout detected */ if (s->health > s->rise) { s->health--; /* still good */