From: Willy Tarreau Date: Thu, 23 Nov 2017 16:34:29 +0000 (+0100) Subject: BUG/MINOR: stream: fix tv_request calculation for applets X-Git-Tag: v1.8.0~54 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ee8269e84d2c10328fe933646e74602c0d17f457;p=thirdparty%2Fhaproxy.git BUG/MINOR: stream: fix tv_request calculation for applets When the stats code was moved to an applet, it wasn't completely cleaned of its usage of the HTTP transaction and it used to store the HTTP status in txn->status and to set the HTTP request date to from within the applet. This is totally wrong because the applet is seen as a server from the HTTP engine, which parses its response, so the http_txn must not be touched there. This was made visible by the cache which would always exhibit a negative TR log, indicating that nowhere in the code we took care of setting s->logs.tv_request while the code above used to continue to hide this. Another side effect of this issue is that under load, if the stats applet call risks to be delayed, the reported t_queue can appear negative by being below tv_request-tv_accept. This patch removes the assignment of tv_request and txn->status from the applet code and instead sets the tv_request if still unset when connecting to the applet. This ensures that all applets report correct request timers now. --- diff --git a/src/stats.c b/src/stats.c index 038c074ca4..6cef1bfc77 100644 --- a/src/stats.c +++ b/src/stats.c @@ -2952,9 +2952,6 @@ static int stats_send_http_headers(struct stream_interface *si) else chunk_appendf(&trash, "\r\n"); - s->txn->status = 200; - s->logs.tv_request = now; - if (ci_putchk(si_ic(si), &trash) == -1) { si_applet_cant_put(si); return 0; @@ -3000,9 +2997,6 @@ static int stats_send_http_redirect(struct stream_interface *si) (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", scope_txt); - s->txn->status = 303; - s->logs.tv_request = now; - if (ci_putchk(si_ic(si), &trash) == -1) { si_applet_cant_put(si); return 0; diff --git a/src/stream.c b/src/stream.c index 25be1e8669..d98c7f98de 100644 --- a/src/stream.c +++ b/src/stream.c @@ -1072,6 +1072,8 @@ static void sess_prepare_conn_req(struct stream *s) return; } + if (tv_iszero(&s->logs.tv_request)) + s->logs.tv_request = now; s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); si->state = SI_ST_EST; si->err_type = SI_ET_NONE;