# HG changeset patch
# User Roman Arutyunyan <arut@nginx.com>
# Date 1500474493 -10800
#      Wed Jul 19 17:28:13 2017 +0300
# Node ID 92bdf92d8ecacc07f9281530e11995c87f6a28a8
# Parent  a27e0c7e198ce989a181fba3c22d0c17e18f84a0
Stream: fixed TCP next upstream (ticket #1317).

Previously, when some data was read from the client before a backend connection
failure, the next upstream could not be chosen.  This was due to a check for
unsent data which only makes sense for UDP.  Now the connection type is checked
as well.

diff --git a/src/stream/ngx_stream_proxy_module.c b/src/stream/ngx_stream_proxy_module.c
--- a/src/stream/ngx_stream_proxy_module.c
+++ b/src/stream/ngx_stream_proxy_module.c
@@ -1665,7 +1665,9 @@ ngx_stream_proxy_next_upstream(ngx_strea
     u = s->upstream;
     pc = u->peer.connection;
 
-    if (u->upstream_out || u->upstream_busy || (pc && pc->buffered)) {
+    if (s->connection->type == SOCK_DGRAM
+        && (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);
