Skip to content

Commit

Permalink
Stream: set action before each recv/send while proxying.
Browse files Browse the repository at this point in the history
Now it's clear from log error message if the error occurred on client or
upstream side.
  • Loading branch information
arut committed Mar 22, 2018
1 parent 0ac5764 commit f39d5e8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/stream/ngx_stream_proxy_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,6 @@ ngx_stream_proxy_init_upstream(ngx_stream_session_t *s)
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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1492,6 +1491,8 @@ ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream,
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;
Expand All @@ -1501,13 +1502,17 @@ ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream,
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 ( ;; ) {

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) {
Expand Down Expand Up @@ -1551,6 +1556,8 @@ ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream,
}
}

c->log->action = recv_action;

n = src->recv(src, b->last, size);

if (n == NGX_AGAIN) {
Expand Down Expand Up @@ -1620,6 +1627,8 @@ ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream,
break;
}

c->log->action = "proxying connection";

if (src->read->eof && dst && (dst->read->eof || !dst->buffered)) {
handler = c->log->handler;
c->log->handler = NULL;
Expand Down

0 comments on commit f39d5e8

Please sign in to comment.