Welcome! Log In Create A New Profile

Advanced

nginx 100% cpu and it may be a nginx bug

November 22, 2011 05:38AM
The function ngx_http_upstream_get_round_robin_peer in nginx will loop for a long period of times when pc->tries equals to 0.

Well then, under what conditions does pc->tries equal to zero?

When executing ngx_http_upstream_get_round_robin_peer for the first time, in some cases it returns NGX_OK while pc->tries equals to 1.

When in ngx_http_upstream_process_header, nginx process may enter the following:
1524 if (n == NGX_ERROR || n == 0) {
1525 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
1526 return;
1527 }

then enter ngx_http_upstream_next function

In the ngx_http_upstream_next,nginx process will call ngx_http_upstream_free_round_robin_peer

2796 if (ft_type != NGX_HTTP_UPSTREAM_FT_NOLIVE) {
2797 u->peer.free(&u->peer, u->peer.data, state);
2798 }


we now enter ngx_http_upstream_free_round_robin_peer.

Pay attention to the following codes in the function:
if (pc->tries) {
pc->tries--;
}

After executing the above, pc->tries changes from 1 to 0.

then the process returns to ngx_http_upstream_next

2892 ngx_http_upstream_connect(r, u);
2893 }

we enter ngx_http_upstream_connect here:

this function will call

1081 rc = ngx_event_connect_peer(&u->peer);


...


It finally enter ngx_http_upstream_get_round_robin_peer again. And then the process will loop for a long time which is unpredictable.
Subject Author Posted

nginx 100% cpu and it may be a nginx bug

wangbin579 November 22, 2011 05:38AM

Re: nginx 100% cpu and it may be a nginx bug

wangbin579 November 22, 2011 05:41AM

Re: nginx 100% cpu and it may be a nginx bug

wangbin579 November 22, 2011 05:44AM

Re: nginx 100% cpu and it may be a nginx bug

wangbin579 November 22, 2011 05:44AM

Re: nginx 100% cpu and it may be a nginx bug

wangbin579 November 22, 2011 05:45AM

Re: nginx 100% cpu and it may be a nginx bug

Maxim Dounin November 22, 2011 06:02AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 208
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready