[nginx] Stream: set action before each recv/send while proxying.

Roman Arutyunyan arut at nginx.com
Fri Mar 23 11:16:49 UTC 2018


details:   http://hg.nginx.org/nginx/rev/ec4d95eed062
branches:  
changeset: 7250:ec4d95eed062
user:      Roman Arutyunyan <arut at nginx.com>
date:      Thu Mar 22 18:43:49 2018 +0300
description:
Stream: set action before each recv/send while proxying.

Now it's clear from log error message if the error occurred on client or
upstream side.

diffstat:

 src/stream/ngx_stream_proxy_module.c |  13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diffs (65 lines):

diff -r 070c972336c4 -r ec4d95eed062 src/stream/ngx_stream_proxy_module.c
--- a/src/stream/ngx_stream_proxy_module.c	Thu Mar 22 19:26:25 2018 +0300
+++ b/src/stream/ngx_stream_proxy_module.c	Thu Mar 22 18:43:49 2018 +0300
@@ -801,8 +801,6 @@ ngx_stream_proxy_init_upstream(ngx_strea
                        NGX_STREAM_UPSTREAM_NOTIFY_CONNECT);
     }
 
-    c->log->action = "proxying connection";
-
     if (u->upstream_buf.start == NULL) {
         p = ngx_pnalloc(c->pool, pscf->buffer_size);
         if (p == NULL) {
@@ -1449,6 +1447,7 @@ static void
 ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream,
     ngx_uint_t do_write)
 {
+    char                         *recv_action, *send_action;
     off_t                        *received, limit;
     size_t                        size, limit_rate;
     ssize_t                       n;
@@ -1492,6 +1491,8 @@ ngx_stream_proxy_process(ngx_stream_sess
         received = &u->received;
         out = &u->downstream_out;
         busy = &u->downstream_busy;
+        recv_action = "proxying and reading from upstream";
+        send_action = "proxying and sending to client";
 
     } else {
         src = c;
@@ -1501,6 +1502,8 @@ ngx_stream_proxy_process(ngx_stream_sess
         received = &s->received;
         out = &u->upstream_out;
         busy = &u->upstream_busy;
+        recv_action = "proxying and reading from client";
+        send_action = "proxying and sending to upstream";
     }
 
     for ( ;; ) {
@@ -1508,6 +1511,8 @@ ngx_stream_proxy_process(ngx_stream_sess
         if (do_write && dst) {
 
             if (*out || *busy || dst->buffered) {
+                c->log->action = send_action;
+
                 rc = ngx_stream_top_filter(s, *out, from_upstream);
 
                 if (rc == NGX_ERROR) {
@@ -1551,6 +1556,8 @@ ngx_stream_proxy_process(ngx_stream_sess
                 }
             }
 
+            c->log->action = recv_action;
+
             n = src->recv(src, b->last, size);
 
             if (n == NGX_AGAIN) {
@@ -1620,6 +1627,8 @@ ngx_stream_proxy_process(ngx_stream_sess
         break;
     }
 
+    c->log->action = "proxying connection";
+
     if (src->read->eof && dst && (dst->read->eof || !dst->buffered)) {
         handler = c->log->handler;
         c->log->handler = NULL;


More information about the nginx-devel mailing list