Welcome! Log In Create A New Profile

Advanced

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

Maxim Dounin
November 22, 2011 06:02AM
Hello!

On Tue, Nov 22, 2011 at 05:38:11AM -0500, wangbin579 wrote:

> 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 }

The ngx_http_upstream_next() will finalize request if tries == 0.

You are probably facing the problem with keepalive backend
connections in 1.0.x (where they aren't officially supported). It
is fixed with this changeset while introducing official keepalive
backend connections support in 1.1.4:

http://trac.nginx.org/nginx/changeset/4116/nginx

Maxim Dounin

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
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: 71
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