﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	uname	nginx_version
1317	"load_balance failed in ngx_stream_proxy_module because of ""pending buffers"""	qleeAI@…		"If s->connection->read->ready is true when entering ngx_stream_proxy_module, ngx_stream_proxy_downstream_handler is called and read some data , stored in u->upstream_out.

If connect to upstream failed and entering ngx_stream_proxy_next_upstream() to connect to next upstrem server. u->upstream_out is not NULL and stream session is finalized.


In function ngx_stream_proxy_next_upstream
{{{

    if (u->upstream_out || u->upstream_busy || (pc && pc->buffered)) {
        ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
                      ""pending buffers on next upstream"");
        ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
        return;
    }
}}}



== Example ==

Obviously the example only used to descript the problem, we don't use it like this on production environment.



Nginx config file like this.

{{{
daemon off;
master_process off;

events {
    worker_connections  1024;
}

stream {
    upstream backend {
        server 10.10.10.10:80;
        server 115.231.25.133:80;
    }
    server {
        listen 80;
        ssl_preread on;
        preread_buffer_size 64;
        proxy_pass backend;
        proxy_connect_timeout 3s;
    }
}

}}}


Using curl to send a HTTP request, Nginx only try the first server.

error.log
{{{
2017/07/12 22:43:37 [error] 25361#0: *1 upstream timed out (110: Connection timed out) while connecting to upstream, client: 127.0.0.1, server: 0.0.0.0:80, upstream: ""10.10.10.10:80"", bytes from/to client:9/0, bytes from/to upstream:0/0
2017/07/12 22:43:37 [error] 25361#0: *1 pending buffers on next upstream while connecting to upstream, client: 127.0.0.1, server: 0.0.0.0:80, upstream: ""10.10.10.10:80"", bytes from/to client:9/0, bytes from/to upstream:0/0

}}}
"	defect	closed	minor	1.13	nginx-module	1.13.x	fixed	stream proxy load_balance	gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609	Linux kenan-desktop 4.4.0-83-generic #106-Ubuntu SMP Mon Jun 26 17:54:43 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux	"nginx version: nginx/1.13.4
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 
configure arguments: --with-debug --with-stream --with-stream_ssl_preread_module --with-pcre --with-zlib=../zlib-1.2.8"
