Mercurial > hg > nginx
comparison src/stream/ngx_stream_proxy_module.c @ 7250:ec4d95eed062
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.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Thu, 22 Mar 2018 18:43:49 +0300 |
parents | 84e53e4735a4 |
children | d27aa9060c95 |
comparison
equal
deleted
inserted
replaced
7249:070c972336c4 | 7250:ec4d95eed062 |
---|---|
799 if (u->peer.notify) { | 799 if (u->peer.notify) { |
800 u->peer.notify(&u->peer, u->peer.data, | 800 u->peer.notify(&u->peer, u->peer.data, |
801 NGX_STREAM_UPSTREAM_NOTIFY_CONNECT); | 801 NGX_STREAM_UPSTREAM_NOTIFY_CONNECT); |
802 } | 802 } |
803 | 803 |
804 c->log->action = "proxying connection"; | |
805 | |
806 if (u->upstream_buf.start == NULL) { | 804 if (u->upstream_buf.start == NULL) { |
807 p = ngx_pnalloc(c->pool, pscf->buffer_size); | 805 p = ngx_pnalloc(c->pool, pscf->buffer_size); |
808 if (p == NULL) { | 806 if (p == NULL) { |
809 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); | 807 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); |
810 return; | 808 return; |
1447 | 1445 |
1448 static void | 1446 static void |
1449 ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream, | 1447 ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream, |
1450 ngx_uint_t do_write) | 1448 ngx_uint_t do_write) |
1451 { | 1449 { |
1450 char *recv_action, *send_action; | |
1452 off_t *received, limit; | 1451 off_t *received, limit; |
1453 size_t size, limit_rate; | 1452 size_t size, limit_rate; |
1454 ssize_t n; | 1453 ssize_t n; |
1455 ngx_buf_t *b; | 1454 ngx_buf_t *b; |
1456 ngx_int_t rc; | 1455 ngx_int_t rc; |
1490 b = &u->upstream_buf; | 1489 b = &u->upstream_buf; |
1491 limit_rate = pscf->download_rate; | 1490 limit_rate = pscf->download_rate; |
1492 received = &u->received; | 1491 received = &u->received; |
1493 out = &u->downstream_out; | 1492 out = &u->downstream_out; |
1494 busy = &u->downstream_busy; | 1493 busy = &u->downstream_busy; |
1494 recv_action = "proxying and reading from upstream"; | |
1495 send_action = "proxying and sending to client"; | |
1495 | 1496 |
1496 } else { | 1497 } else { |
1497 src = c; | 1498 src = c; |
1498 dst = pc; | 1499 dst = pc; |
1499 b = &u->downstream_buf; | 1500 b = &u->downstream_buf; |
1500 limit_rate = pscf->upload_rate; | 1501 limit_rate = pscf->upload_rate; |
1501 received = &s->received; | 1502 received = &s->received; |
1502 out = &u->upstream_out; | 1503 out = &u->upstream_out; |
1503 busy = &u->upstream_busy; | 1504 busy = &u->upstream_busy; |
1505 recv_action = "proxying and reading from client"; | |
1506 send_action = "proxying and sending to upstream"; | |
1504 } | 1507 } |
1505 | 1508 |
1506 for ( ;; ) { | 1509 for ( ;; ) { |
1507 | 1510 |
1508 if (do_write && dst) { | 1511 if (do_write && dst) { |
1509 | 1512 |
1510 if (*out || *busy || dst->buffered) { | 1513 if (*out || *busy || dst->buffered) { |
1514 c->log->action = send_action; | |
1515 | |
1511 rc = ngx_stream_top_filter(s, *out, from_upstream); | 1516 rc = ngx_stream_top_filter(s, *out, from_upstream); |
1512 | 1517 |
1513 if (rc == NGX_ERROR) { | 1518 if (rc == NGX_ERROR) { |
1514 if (c->type == SOCK_DGRAM && !from_upstream) { | 1519 if (c->type == SOCK_DGRAM && !from_upstream) { |
1515 ngx_stream_proxy_next_upstream(s); | 1520 ngx_stream_proxy_next_upstream(s); |
1549 if ((off_t) size > limit) { | 1554 if ((off_t) size > limit) { |
1550 size = (size_t) limit; | 1555 size = (size_t) limit; |
1551 } | 1556 } |
1552 } | 1557 } |
1553 | 1558 |
1559 c->log->action = recv_action; | |
1560 | |
1554 n = src->recv(src, b->last, size); | 1561 n = src->recv(src, b->last, size); |
1555 | 1562 |
1556 if (n == NGX_AGAIN) { | 1563 if (n == NGX_AGAIN) { |
1557 break; | 1564 break; |
1558 } | 1565 } |
1617 } | 1624 } |
1618 } | 1625 } |
1619 | 1626 |
1620 break; | 1627 break; |
1621 } | 1628 } |
1629 | |
1630 c->log->action = "proxying connection"; | |
1622 | 1631 |
1623 if (src->read->eof && dst && (dst->read->eof || !dst->buffered)) { | 1632 if (src->read->eof && dst && (dst->read->eof || !dst->buffered)) { |
1624 handler = c->log->handler; | 1633 handler = c->log->handler; |
1625 c->log->handler = NULL; | 1634 c->log->handler = NULL; |
1626 | 1635 |