Race condition in limit_zone/limit_conn?

Barry Jaspan barry.jaspan at acquia.com
Tue May 4 20:10:26 MSD 2010


Maxim,

Thank you for your reply.

On Mon, May 3, 2010 at 7:58 PM, Maxim Dounin <mdounin at mdounin.ru> wrote:
> You had at least 7 connections (*1, *2, *4, *6, *8, *9, *10)
> during the test.  First 3 were passed through, others were
> rejected. ... Most likely you configured nginx to proxy to itself and this
> causes extra connections.

I understand how making nginx proxy to itself would cause extra
connections and how those might make all of the initial connections
fail. If the limit is 3, I open 3, then each of those 3 attempt to
proxy to nginx again, nginx will return 503 to the proxy request which
will then be returned to the original requests.

However, I do not see how that is happening in my case. I have reduced
my configuration file to a minimum. Here it is:

---- snip snip ----
user              nginx;
worker_processes  10;
error_log         /var/log/nginx/error.log debug;
pid               /var/run/nginx.pid;
events {
    worker_connections  2048;
}
http {
  proxy_set_header Host $host;
  limit_zone max_conn $host 10m;
  limit_conn max_conn 3;
  server {
    listen       80;
    server_name _;
    location / {
      proxy_pass http://10.252.86.98;
    }
  }
}
---- snip snip ----

Does this config file make nginx proxy to itself? I do not see how.
But with this file, when I run the command

# ab -v 3 -c 4 -n 4 'http://maxcon1.bjaspan.acquia-sites.com/sleep.php?sleep=15'

ab shows that all four requests fail with status 503 and I get the
nginx error log output:

# tail -f /var/log/nginx/error.log  | grep limit
2010/05/04 16:06:23 [debug] 4215#0: *1 limit zone: 265A3FCB 1
2010/05/04 16:06:23 [debug] 4215#0: *2 limit zone: 265A3FCB 2
2010/05/04 16:06:23 [debug] 4215#0: *4 limit zone: 265A3FCB 3
2010/05/04 16:06:23 [error] 4215#0: *6 limiting connections by zone
"max_conn", client: 64.119.156.90, server: _, request: "GET
/sleep.php?sleep=15 HTTP/1.0", host:
"maxcon1.bjaspan.acquia-sites.com"
2010/05/04 16:06:23 [debug] 4215#0: *6 http write filter limit 0
2010/05/04 16:06:23 [error] 4215#0: *8 limiting connections by zone
"max_conn", client: 64.119.156.90, server: _, request: "GET
/sleep.php?sleep=15 HTTP/1.0", host:
"maxcon1.bjaspan.acquia-sites.com"
2010/05/04 16:06:23 [debug] 4215#0: *8 http write filter limit 0
2010/05/04 16:06:23 [error] 4215#0: *9 limiting connections by zone
"max_conn", client: 64.119.156.90, server: _, request: "GET
/sleep.php?sleep=15 HTTP/1.0", host:
"maxcon1.bjaspan.acquia-sites.com"
2010/05/04 16:06:23 [debug] 4215#0: *9 http write filter limit 0
2010/05/04 16:06:23 [error] 4215#0: *10 limiting connections by zone
"max_conn", client: 64.119.156.90, server: _, request: "GET
/sleep.php?sleep=15 HTTP/1.0", host:
"maxcon1.bjaspan.acquia-sites.com"
2010/05/04 16:06:23 [debug] 4215#0: *10 http write filter limit 0
2010/05/04 16:06:23 [debug] 4215#0: limit zone cleanup: 265A3FCB 3
2010/05/04 16:06:23 [debug] 4215#0: limit zone cleanup: 265A3FCB 2
2010/05/04 16:06:23 [debug] 4215#0: limit zone cleanup: 265A3FCB 1

Any thoughts?

Thanks,

Barry



More information about the nginx mailing list