[PATCH] ngx_gzip might hang the request for slow downstreams

Yichun Zhang (agentzh) agentzh at gmail.com
Sat Oct 26 00:16:24 UTC 2013


Hello!

I've noticed a request hang due to an issue in
ngx_http_gzip_filter_module's output body filter. Basically when the
downstream connection is slow to write to, a write event can trigger a
call of ngx_http_output_filter(r, NULL) but ngx_gzip's body filter
does not pass the NULL chain link to its downstream filters when its
ctx->out == NULL, leading to the downstream connection not flushed at
all and a hang.

This issue exists in both nginx 1.4.3 and 1.5.6.

The following patch fixes the test case on my side. Comments welcome!

Thanks!
-agentzh

--- nginx-1.4.3/src/http/modules/ngx_http_gzip_filter_module.c
2013-10-08 05:07:14.000000000 -0700
+++ nginx-1.4.3-patched/src/http/modules/ngx_http_gzip_filter_module.c
2013-10-25 17:00:00.712697908 -0700
@@ -433,7 +433,15 @@ ngx_http_gzip_body_filter(ngx_http_reque
         if (ctx->out == NULL) {
             ngx_http_gzip_filter_free_copy_buf(r, ctx);

-            return ctx->busy ? NGX_AGAIN : NGX_OK;
+            if (ctx->busy) {
+                if (in == NULL) {
+                    return ngx_http_next_body_filter(r, NULL);
+                }
+
+                return NGX_AGAIN;
+            }
+
+            return NGX_OK;
         }

         if (!ctx->gzheader) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginx-1.4.3-gzip_flush_bug.patch
Type: text/x-patch
Size: 686 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20131025/58547596/attachment.bin>


More information about the nginx-devel mailing list