Welcome! Log In Create A New Profile

Advanced

[PATCH] Upstream: avoid closing client connection in edge case

Justin Li
March 08, 2016 10:42PM
# HG changeset patch
# User Justin Li <jli.justinli@gmail.com>
# Date 1457494315 18000
# Tue Mar 08 22:31:55 2016 -0500
# Node ID 80d1d2148e4bd82eb27e50fba91fa36fed039871
# Parent c5f81dcf97a79576138917501c9a6cc6f53ee930
Upstream: avoid closing client connection in edge case.

If proxy_cache is enabled, and proxy_no_cache tests true, it was previously
possible for the client connection to be closed after a 304. The fix is to
recheck r->header_only after the final cacheability is determined, and end the
request if no longer cacheable.

Example configuration:

proxy_cache foo;
proxy_cache_bypass 1;
proxy_no_cache 1;

If a client sends If-None-Match, and the upstream server returns 200 with a
matching ETag, no body should be returned to the client. At the start of
ngx_http_upstream_send_response proxy_no_cache is not yet tested, thus cacheable
is still 1 and downstream_error is set.

However, by the time the downstream_error check is done in process_request,
proxy_no_cache has been tested and cacheable is set to 0. The client connection
is then closed, regardless of keepalive.

diff -r c5f81dcf97a7 -r 80d1d2148e4b src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c Thu Mar 03 21:14:19 2016 +0300
+++ b/src/http/ngx_http_upstream.c Tue Mar 08 22:31:55 2016 -0500
@@ -2861,6 +2861,11 @@ ngx_http_upstream_send_response(ngx_http
ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
}

+ if (r->header_only && !u->cacheable && !u->store) {
+ ngx_http_upstream_finalize_request(r, u, 0);
+ return;
+ }
+
#endif

p = u->pipe;

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Upstream: avoid closing client connection in edge case

Justin Li 306 March 08, 2016 10:42PM

Re: [PATCH] Upstream: avoid closing client connection in edge case

Maxim Dounin 188 March 10, 2016 03:40PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 180
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready