# Bug Report: error\_page causes hot looping under heavy load

**URL:** <https://www.ruby-forum.com/t/bug-report-error-page-causes-hot-looping-under-heavy-load/218403>\
**Category:** NGINX\
**Created:** [March 30, 2012, 2:53pm UTC](https://www.ruby-forum.com/t/bug-report-error-page-causes-hot-looping-under-heavy-load/218403 "2012-03-30T14:53:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 30, 2012, 2:53pm UTC](https://www.ruby-forum.com/t/bug-report-error-page-causes-hot-looping-under-heavy-load/218403/1 "2012-03-30T14:53:49Z")

</div>

I compiled a stable release 1.0.14 with no 3rd party modules and under  
heavy load, gdb is showing hot looping around when error\_page directive  
is  
used. The CPU (all 8 cores) reaches 100% usage and the server stops  
responding to further requests

I am happy to share my configurations but its a very simple arrangement  
with varnish server being the backend for proxy\_pass. I am using  
apache-benchmark to test it.

Thanks  
Sparsh G.

---

<div class="post-metadata">

**Author:** ![Sparsh\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@Sparsh\_G](https://www.ruby-forum.com/u/Sparsh_G)\
**Post date:** [March 30, 2012, 3:37pm UTC](https://www.ruby-forum.com/t/bug-report-error-page-causes-hot-looping-under-heavy-load/218403/2 "2012-03-30T15:37:14Z")

</div>

Upon further debugging, the possible issue is at the following line:

src/http/ngx\_http\_upstream\_round\_robin.c:433  
for ( ;; ) {  
rrp-\>current = ngx\_http\_upstream\_get\_peer(rrp-\>peers);

```
           ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
                          "get rr peer, current: %ui %i",
                          rrp->current,

```

rrp-\>peers-\>peer[rrp-\>current].current\_weight);

```
           n = rrp->current / (8 * sizeof(uintptr_t));
           m = (uintptr_t) 1 << rrp->current % (8 * 

```

sizeof(uintptr\_t));

The pc-\>tries is a ridiculously large number, which causes looping. Here  
is  
the configuration used to reproduce the error:

worker\_processes 1;  
worker\_rlimit\_nofile 32768;  
error\_log /var/log/nginx/error.log warn;  
events { worker\_connections 16384; use epoll; }

http {  
access\_log off;

```
upstream a {
        server 10.56.140.8 backup;
        server 10.56.140.2 backup;
        server 10.56.140.4 backup;
        server 10.56.140.6 backup;
}

upstream b {
        server 10.56.140.16 max_fails=100 fail_timeout=5s;
        server 10.56.140.8 backup;
        server 10.56.140.2 backup;
        server 10.56.140.4 backup;
        server 10.56.140.6 backup;
}

server {
    listen 80;

    location = /j.php {
        include /etc/nginx/proxy.conf; #with some timeout variables

```

which are not relevant here I think  
proxy\_pass [http://b](http://b);  
error\_page 403 404 500 502 503 504 = @fallback;  
}

```
    location @fallback {
            proxy_pass http://a;
    }

```

}  
}

Sparsh G.

---

<div class="post-metadata">

**Author:** ![Sparsh\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@Sparsh\_G](https://www.ruby-forum.com/u/Sparsh_G)\
**Post date:** [March 31, 2012, 1:54am UTC](https://www.ruby-forum.com/t/bug-report-error-page-causes-hot-looping-under-heavy-load/218403/3 "2012-03-31T01:54:20Z")

</div>

Hello!

On Fri, Mar 30, 2012 at 07:06:17PM +0530, Sparsh G. wrote:

> rrp-\>peers-\>peer[rrp-\>current].current\_weight);  
> worker\_rlimit\_nofile 32768;  
> server 10.56.140.6 backup;  
> server {  
> proxy\_pass [http://a](http://a);  
> }  
> }  
> }

Upstream “a” have only backup servers, and this is what causes  
problems. This is in fact configuration error (you have to define  
at least one non-backup server, else “backup” flag doesn’t make  
sense). But obviously this should be either rejected during  
configuration parsing or handled somehow, CPU hog is a bug, thank  
you for report.

With the following patch nginx will reject such configuration  
during configuration parsing:

— a/src/http/ngx\_http\_upstream\_round\_robin.c  
+++ b/src/http/ngx\_http\_upstream\_round\_robin.c  
@@ -49,6 +49,13 @@ ngx\_http\_upstream\_init\_round\_robin(ngx\_c  
n += server[i].naddrs;  
}

- 

```
   if (n == 0) {

```

- 

```
       ngx_log_error(NGX_LOG_EMERG, cf->log, 0,

```

- 

```
                     "no servers in upstream \"%V\" in %s:%ui",

```

- 

```
                     &us->host, us->file_name, us->line);

```

- 

```
       return NGX_ERROR;

```

- 

```
   }

```

- 

```
   peers = ngx_pcalloc(cf->pool, 

```

sizeof(ngx\_http\_upstream\_rr\_peers\_t)  
+ sizeof(ngx\_http\_upstream\_rr\_peer\_t) \*  
(n - 1));  
if (peers == NULL) {

Maxim D.

> > responding to further requests
> > 
> > I am happy to share my configurations but its a very simple arrangement  
> > with varnish server being the backend for proxy\_pass. I am using  
> > apache-benchmark to test it.
> > 
> > Thanks  
> > Sparsh G.
