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 two options:

  1. If there is no proxy_cache active: disable proxy_buffering with off.
  2. If there is a cache active or buffering is appreciated (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
@ 08 Oct 2016, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About