dracoblue.net

Hanging subrequests in Nginx

While I was working on lua-native-ssi-nginx (an opinionated lua replacement of nginx's ssi directive), I ran into the following issue:

The proxy_pass requests seemed to hang (or lock) as soon as the response was too big.

Even with nginx in debug mode, I could only see this in the error.log:

2016/10/08 10:47:19 [debug] 31895#0: *1337 http upstream request: "/sub-request?"
2016/10/08 10:47:19 [debug] 31895#0: *1337 http upstream dummy handler
2016/10/08 10:47:19 [debug] 31895#0: *1337 http upstream request: "/sub-request?"
2016/10/08 10:47:19 [debug] 31895#0: *1337 http upstream dummy handler
2016/10/08 10:47:19 [debug] 31895#0: *1337 http upstream request: "/sub-request?"

Even though I suspected ngx.location.capture to behave slightly wrong, it turned out that my proxy configuration was wrong.

I had:

proxy_buffer_size          16k;
proxy_buffering         on;
proxy_max_temp_file_size 0;
proxy_pass http://127.0.0.1:4777;

in my setup.

This actually means for nginx: buffer everything up to 16k (because of proxy_buffer_size 16k and proxy_buffering on), but do not store anything bigger than this in temp files (because of proxy_max_temp_file_size 0).

To fix the hanging subrequests in nginx, I had to options:

  1. If there is no proxy_cache active: disable proxy_buffering with off.
  2. If there is a cache active or buffering is appriciated (e.g. in case of slow clients): set proxy_max_temp_file_size back to the default of 1024m.

So I go with the following setup now:

proxy_buffer_size          16k;
proxy_buffering         on;
proxy_max_temp_file_size 1024m;
proxy_pass http://127.0.0.1:4777;

In lua, nginx, open source by @ 09 Oct 2016

comments powered by Disqus

Recent Files

Advertisement

Recent Dev-Articles

Read recently

About

Blogroll