BUG/MEDIUM: http: Close streams for connections closed before a redirect
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 11 Sep 2017 07:27:29 +0000 (09:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 11 Sep 2017 15:39:21 +0000 (17:39 +0200)
A previous fix was made to prevent the connection to a server if a redirect was
performed during the request processing when we wait to keep the client
connection alive. This fix introduced a pernicious bug. If a client closes its
connection immediately after sending a request, it is possible to keep stream
alive infinitely. This happens when the connection closure is caught when the
request is received, before the request parsing.

To be more specific, this happens because the close event is not "forwarded",
first because of the call to "channel_dont_connect" in the function
"http_apply_redirect_rule", then because we want to keep the client connection
alive, we explicitly call "channel_dont_close" in the function
"http_request_forward_body".

So, to fix the bug, instead of blocking the server connection, we force its
shutdown. This will force the stream to re-evaluate all connexions states. So it
will detect the client has closed its connection.

This patch must be backported in 1.7.

src/proto_http.c

index 7bdd19d..634a002 100644 (file)
@@ -4237,8 +4237,8 @@ static int http_apply_redirect_rule(struct redirect_rule *rule, struct stream *s
                /* Trim any possible response */
                res->chn->buf->i = 0;
                res->next = res->sov = 0;
-               /* If not already done, don't perform any connection establishment */
-               channel_dont_connect(req->chn);
+               /* let the server side turn to SI_ST_CLO */
+               channel_shutw_now(req->chn);
        } else {
                /* keep-alive not possible */
                if (unlikely(txn->flags & TX_USE_PX_CONN)) {