]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: unique_id: HTTP request counter must be unique!
authorWilly Tarreau <w@1wt.eu>
Tue, 13 Aug 2013 15:51:07 +0000 (17:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 13 Aug 2013 15:52:20 +0000 (17:52 +0200)
The HTTP request counter is incremented non atomically, which means that
many requests can log the same ID. Let's increment it when it is consumed
so that we avoid this case.

This bug was reported by Patrick Hemmer. It's 1.5-specific and does not
need to be backported.

include/types/global.h
src/log.c
src/proto_http.c

index 41cd67fbef1da36b0a10825de04ae5213f11f703..cfc3d23bc0a9dc8f3369bbe8c2dbec70ab0baf36 100644 (file)
@@ -90,7 +90,7 @@ struct global {
        int rlimit_memmax;      /* default ulimit-d in megs value : 0=unset */
        long maxzlibmem;        /* max RAM for zlib in bytes */
        int mode;
-       unsigned int req_count; /* HTTP request counter */
+       unsigned int req_count; /* HTTP request counter for logs and unique_id */
        int last_checks;
        int spread_checks;
        char *chroot;
index 8f8fd8f8c4fb18bbdfeb87f33938b35c97d5993e..369dc34b197094ecac4a5f464ef5e0a2eea685d5 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -1448,13 +1448,13 @@ int build_logline(struct session *s, char *dst, size_t maxsize, struct list *lis
 
                        case LOG_FMT_COUNTER: // %rt
                                if (tmp->options & LOG_OPT_HEXA) {
-                                       iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", global.req_count);
+                                       iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", global.req_count++);
                                        if (iret < 0 || iret > dst + maxsize - tmplog)
                                                goto out;
                                        last_isspace = 0;
                                        tmplog += iret;
                                } else {
-                                       ret = ltoa_o(global.req_count, tmplog, dst + maxsize - tmplog);
+                                       ret = ltoa_o(global.req_count++, tmplog, dst + maxsize - tmplog);
                                        if (ret == NULL)
                                                goto out;
                                        tmplog = ret;
index 3ef64728bcbb28e44395a170f536de8fc31dcb5f..8d6eaf51912d7d3d430b439c54e4383f2d3edfe0 100644 (file)
@@ -8289,8 +8289,6 @@ void http_init_txn(struct session *s)
        txn->flags = 0;
        txn->status = -1;
 
-       global.req_count++;
-
        txn->cookie_first_date = 0;
        txn->cookie_last_date = 0;