Upstream: flush low-level buffers on write retry.

If the data to write is bigger than what the socket can send and the
reminder is smaller than NGX_SSL_BUFSIZE, then SSL_write() fails with
SSL_ERROR_WANT_WRITE. The reminder of payload however is successfully
copied to the low-level buffer and all the output chain buffers are
flushed. This means that retry logic doesn't work because
ngx_http_upstream_process_non_buffered_request() checks only if there's
anything in the output chain buffers and ignores the fact that something
may be buffered in low-level parts of the stack.

Change-Id: I7ae8279dd3f95e69853e83ab14a707e30efe66a8
Signed-off-by: Patryk Lesiewicz <patryk@google.com>
Reviewed-on: https://nginx-review.googlesource.com/3260
Reviewed-by: Piotr Sikora <piotrsikora@google.com>
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index f4bd6dc..876357d 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -3608,7 +3608,7 @@
 
         if (do_write) {
 
-            if (u->out_bufs || u->busy_bufs) {
+            if (u->out_bufs || u->busy_bufs || downstream->buffered) {
                 rc = ngx_http_output_filter(r, u->out_bufs);
 
                 if (rc == NGX_ERROR) {