Opened 4 years ago

Closed 4 years ago

#1136 closed defect (wontfix)

`ngx_stream_proxy_process_connection` does not terminate udp session correctly with param `proxy_responses`

Reported by: lrita@… Owned by:
Priority: minor Milestone:
Component: nginx-module Version: 1.11.x
Keywords: stream udp proxy_responses Cc:
uname -a: Linux localhost.localdomain 3.10.0-327.36.3.el7.x86_64 #1 SMP Mon Oct 24 16:09:20 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: openresty/1.11.2.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/nginx --with-debug --with-cc-opt='-DNGX_LUA_USE_ASSERT -DNGX_LUA_ABORT_AT_PANIC -O2' --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.60 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.7 --add-module=../ngx_lua_upstream-0.06 --add-module=../headers-more-nginx-module-0.32 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.17 --add-module=../redis2-nginx-module-0.13 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/usr/luajit/lib --with-stream --with-http_ssl_module

Description

I have a service which collects some statistics informations by udp protocol, only receive request and no response. So I use nginx as a loadbalancing in front of the service.
My nginx.conf :

stream {
        upstream hund {
                server 127.0.0.1:5000;
                server 127.0.0.1:5001;
                server 127.0.0.1:5002;
        }
        server {
                listen 4000 udp;
                proxy_timeout 0;
                proxy_responses 0;
                proxy_pass hund;
        }
}

But the nginx mark the servers of upstream failed. The proxy_responses means backend server has no response in doc. When I view the code of this issue, I find ngx_stream_proxy_process_connection maybe not terminate udp session correctly.

In my opinion the code of ngx_stream_proxy_process_connection

            if (s->connection->type == SOCK_DGRAM) {
                if (pscf->responses == NGX_MAX_INT32_VALUE) {

                    /*
                     * successfully terminate timed out UDP session
                     * with unspecified number of responses
                     */

                    pc->read->ready = 0;
                    pc->read->eof = 1;

                    ngx_stream_proxy_process(s, 1, 0);
                    return;
                }

                if (u->received == 0) {
                    ngx_stream_proxy_next_upstream(s);
                    return;
                }
            }

shound be

            if (s->connection->type == SOCK_DGRAM) {
                if (pscf->responses == 0 || pscf->responses == NGX_MAX_INT32_VALUE) {

                    /*
                     * successfully terminate timed out UDP session
                     * with unspecified number of responses or no response
                     */

                    pc->read->ready = 0;
                    pc->read->eof = 1;

                    ngx_stream_proxy_process(s, 1, 0);
                    return;
                }

                if (u->received == 0) {
                    ngx_stream_proxy_next_upstream(s);
                    return;
                }
            }

Change History (1)

comment:1 by Roman Arutyunyan, 4 years ago

Resolution: wontfix
Status: newclosed

What were you expecting by setting "proxy_timeout 0;" ?

In your case this timeout expires before udp session is finalized normally. This is why you have the error. Just remove this directive and it will work.

The code in ngx_stream_proxy_process_connection(), you have mentioned, is supposed to gracefully shut down a udp session when no proxy_responses is specified. Your case has nothing to do with that.

Note: See TracTickets for help on using tickets.