]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: logs: Report the true number of retries if there was no connection
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 16 Apr 2021 09:24:20 +0000 (11:24 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 19 Apr 2021 06:52:17 +0000 (08:52 +0200)
When the session is aborted before any connection attempt to any server, the
number of connection retries reported in the logs is wrong. It happens
because when the retries counter is not strictly positive, we consider the
max number of retries was reached and the backend retries value is used. It
is obviously wrong when no connectioh was performed.

In fact, at this stage, the retries counter is initialized to 0. But the
backend stream-interface is in the INI state. Once it is set to SI_ST_REQ,
the counter is set to the backend value. And it is the only possible state
transition from INI state. Thus it is safe to rely on it to fix the bug.

This patch must be backported to all stable versions.

src/log.c

index 79166bfe271f0a0f99a27763daa950a4f7e77e3f..c3437b5ccaf8ab4aeea7326cc0debae479beeb32 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -2797,9 +2797,10 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
                        case LOG_FMT_RETRIES:  // %rq
                                if (s_flags & SF_REDISP)
                                        LOGCHAR('+');
-                               ret = ltoa_o((s && s->si[1].conn_retries > 0) ?
-                                               (be->conn_retries - s->si[1].conn_retries) :
-                                               be->conn_retries, tmplog, dst + maxsize - tmplog);
+                               ret = ltoa_o(((s && s->si[1].conn_retries > 0)
+                                             ? (be->conn_retries - s->si[1].conn_retries)
+                                             : ((s && s->si[1].state != SI_ST_INI) ? be->conn_retries : 0)),
+                                            tmplog, dst + maxsize - tmplog);
                                if (ret == NULL)
                                        goto out;
                                tmplog = ret;