nginx svn head segmeant fault with simple reverse proxy if backend www server can't be reached

Delta Yeh delta.yeh at gmail.com
Tue Sep 20 06:10:09 UTC 2011


 I've merged proxy_bind variable   patch from Maxim, so there is some
difference of line number in some source file.


nginx: nginx version: 1.1.3
nginx: built by gcc 4.3.5 (Debian 4.3.5-4)
nginx: TLS SNI support enabled
nginx: configure arguments: --prefix=/usr --pid-path=/usr/var
--with-cpu-opt=pentium4 --with-pcre --with-ipv6
--without-http_autoindex_module --without-http_ssi_module
--without-http_empty_gif_module --without-http_memcached_module
--without-http_charset_module --without-http_split_clients_module
--with-http_stub_status_module --with-http_ssl_module
--with-http_realip_module --with-http_sub_module
--with-http_geoip_module --add-module=src/http/modules/ngx_devel_kit
--add-module=src/http/modules/lua-nginx
--add-module=src/http/modules/headers_more



The nginx config is simple proxy


{

....
proxy_pass http://1.2.3.4/;

....
}




# wget http://1.2.3.4/
Connecting to 1.2.3.4 (1.2.3.4:80)
wget: can't connect to remote host (1.2.3.4): Network is unreachable



If I run nginx in a box which can reach backed server , nginx is OK.


(gdb) bt
#0  ngx_destroy_pool (pool=0x0) at src/core/ngx_palloc.c:50
#1  0x0808f8a8 in ngx_http_upstream_finalize_request (r=0x810fbc8,
    u=0x8115e30, rc=502) at src/http/ngx_http_upstream.c:3024
#2  0x08092ad8 in ngx_http_upstream_next (r=0x810fbc8, u=0x8115e30, ft_type=2)
    at src/http/ngx_http_upstream.c:2910
#3  0x08091d98 in ngx_http_upstream_connect (r=0x810fbc8, u=0x8115e30)
    at src/http/ngx_http_upstream.c:1136
#4  0x08092902 in ngx_http_upstream_init_request (r=0x810fbc8)
    at src/http/ngx_http_upstream.c:643
#5  0x08092992 in ngx_http_upstream_init (r=0x810fbc8)
    at src/http/ngx_http_upstream.c:443
#6  0x080894cf in ngx_http_read_client_request_body (r=0x810fbc8,
    post_handler=0x8092919 <ngx_http_upstream_init>)
    at src/http/ngx_http_request_body.c:58
#7  0x080a57b8 in ngx_http_proxy_handler (r=0x810fbc8)
    at src/http/modules/ngx_http_proxy_module.c:666
#8  0x0807f60d in ngx_http_core_content_phase (r=0x810fbc8, ph=0x8123b44)
    at src/http/ngx_http_core_module.c:1363
#9  0x0807b075 in ngx_http_core_run_phases (r=0x810fbc8)
    at src/http/ngx_http_core_module.c:861
#10 0x0807b174 in ngx_http_handler (r=0x81162fc)
    at src/http/ngx_http_core_module.c:844
#11 0x08083b35 in ngx_http_process_request (r=0x810fbc8)
---Type <return> to continue, or q <return> to quit---
    at src/http/ngx_http_request.c:1665
#12 0x08084140 in ngx_http_process_request_headers (rev=0x8146c2c)
    at src/http/ngx_http_request.c:1111
#13 0x080845fe in ngx_http_process_request_line (rev=0x8146c2c)
    at src/http/ngx_http_request.c:911
#14 0x08081df7 in ngx_http_init_request (rev=0x8146c2c)
    at src/http/ngx_http_request.c:518
#15 0x08074f06 in ngx_epoll_process_events (cycle=0x81100c8, timer=60000,
    flags=<value optimized out>) at src/event/modules/ngx_epoll_module.c:670
#16 0x0806dea7 in ngx_process_events_and_timers (cycle=0x81100c8)
    at src/event/ngx_event.c:245
#17 0x08072e4c in ngx_single_process_cycle (cycle=0x81100c8)
    at src/os/unix/ngx_process_cycle.c:311
#18 0x0805a720 in main (argc=3, argv=0xbfd5cfb4) at src/core/nginx.c:402


(gdb) frame 1
#1  0x0808f8a8 in ngx_http_upstream_finalize_request (r=0x810fbc8,
    u=0x8115e30, rc=502) at src/http/ngx_http_upstream.c:3024
3024    in src/http/ngx_http_upstream.c
(gdb) info args
r = (ngx_http_request_t *) 0x810fbc8
u = (ngx_http_upstream_t *) 0x8115e30
rc = 502


(gdb) frame 1
#1  0x0808f8a8 in ngx_http_upstream_finalize_request (r=0x810fbc8,
    u=0x8115e30, rc=502) at src/http/ngx_http_upstream.c:3024
3024    in src/http/ngx_http_upstream.c
(gdb) p u->peer.connection->fd
$16 = 11
(gdb) p u->peer.connection->pool
$15 = (ngx_pool_t *) 0x0

my ngx_http_upstream.c  3024 is :


   ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                       "close http upstream connection: %d",
                       u->peer.connection->fd);

3024---->        ngx_destroy_pool(u->peer.connection->pool);





(gdb) frame 2
#2  0x08092ad8 in ngx_http_upstream_next (r=0x810fbc8, u=0x8115e30, ft_type=2)
    at src/http/ngx_http_upstream.c:2910
2910    in src/http/ngx_http_upstream.c
(gdb) info locals
status = 135357180
(gdb) info args
r = (ngx_http_request_t *) 0x810fbc8
u = (ngx_http_upstream_t *) 0x8115e30
ft_type = 2

(gdb) p u->state->status
$23 = 502
(gdb) p status
$24 = 135357180


 if (status) {
        u->state->status = status;

        if (u->peer.tries == 0 || !(u->conf->next_upstream & ft_type)) {

#if (NGX_HTTP_CACHE)

            if (u->cache_status == NGX_HTTP_CACHE_EXPIRED
                && (u->conf->cache_use_stale & ft_type))
            {
                ngx_int_t  rc;

                rc = u->reinit_request(r);

                if (rc == NGX_OK) {
                    u->cache_status = NGX_HTTP_CACHE_STALE;
                    rc = ngx_http_upstream_cache_send(r, u);
                }

                ngx_http_upstream_finalize_request(r, u, rc);
                return;
            }
#endif

2910--->            ngx_http_upstream_finalize_request(r, u, status);
            return;
        }
    }



Because  ft == 2(NGX_HTTP_UPSTREAM_FT_ERROR)
if (ft_type != NGX_HTTP_UPSTREAM_FT_NOLIVE) {
        u->peer.free(&u->peer, u->peer.data, state);
    }
(gdb) frame 2
#2  0x08092ad8 in ngx_http_upstream_next (r=0x810fbc8, u=0x8115e30, ft_type=2)
    at src/http/ngx_http_upstream.c:2910
2910    in src/http/ngx_http_upstream.c

(gdb) p  u->peer
$25 = {connection = 0x812dcb8, sockaddr = 0x8120918, socklen = 16,
  name = 0x812095c, tries = 0,
  get = 0x8092f24 <ngx_http_upstream_get_round_robin_peer>,
  free = 0x8092dc7 <ngx_http_upstream_free_round_robin_peer>,
  data = 0x8116328,
  set_session = 0x8092ef9 <ngx_http_upstream_set_round_robin_peer_session>,
  save_session = 0x8092eb2 <ngx_http_upstream_save_round_robin_peer_session>,
  local = 0x0, rcvbuf = 0, log = 0x810faf8, cached = 0, log_error = 1,
  transparent = 0}



More information about the nginx-devel mailing list