Mercurial > hg > nginx
comparison src/stream/ngx_stream_proxy_module.c @ 8044:457afc332c67
Stream: don't flush empty buffers created for read errors.
When we generate the last_buf buffer for an UDP upstream recv error, it does
not contain any data from the wire. ngx_stream_write_filter attempts to forward
it anyways, which is incorrect (e.g., UDP upstream ECONNREFUSED will be
translated to an empty packet).
This happens because we mark the buffer as both 'flush' and 'last_buf', and
ngx_stream_write_filter has special handling for flush with certain types of
connections (see d127837c714f, 32b0ba4855a6). The flags are meant to be
mutually exclusive, so the fix is to ensure that flush and last_buf are not set
at the same time.
Reproduction:
stream {
upstream unreachable {
server 127.0.0.1:8880;
}
server {
listen 127.0.0.1:8998 udp;
proxy_pass unreachable;
}
}
1 0.000000000 127.0.0.1 → 127.0.0.1 UDP 47 45588 → 8998 Len=5
2 0.000166300 127.0.0.1 → 127.0.0.1 UDP 47 51149 → 8880 Len=5
3 0.000172600 127.0.0.1 → 127.0.0.1 ICMP 75 Destination unreachable (Port
unreachable)
4 0.000202400 127.0.0.1 → 127.0.0.1 UDP 42 8998 → 45588 Len=0
Fixes d127837c714f.
author | Aleksei Bavshin <a.bavshin@f5.com> |
---|---|
date | Mon, 23 May 2022 11:29:44 -0700 |
parents | c7e25324be11 |
children | 9d98d524bd02 8d0753760546 |
comparison
equal
deleted
inserted
replaced
8043:1afd19dc7161 | 8044:457afc332c67 |
---|---|
1735 cl->buf->last = b->last + n; | 1735 cl->buf->last = b->last + n; |
1736 cl->buf->tag = (ngx_buf_tag_t) &ngx_stream_proxy_module; | 1736 cl->buf->tag = (ngx_buf_tag_t) &ngx_stream_proxy_module; |
1737 | 1737 |
1738 cl->buf->temporary = (n ? 1 : 0); | 1738 cl->buf->temporary = (n ? 1 : 0); |
1739 cl->buf->last_buf = src->read->eof; | 1739 cl->buf->last_buf = src->read->eof; |
1740 cl->buf->flush = 1; | 1740 cl->buf->flush = !src->read->eof; |
1741 | 1741 |
1742 (*packets)++; | 1742 (*packets)++; |
1743 *received += n; | 1743 *received += n; |
1744 b->last += n; | 1744 b->last += n; |
1745 do_write = 1; | 1745 do_write = 1; |