[PATCH 1 of 2] Stream: removed empty input buffer after peek preread

Roman Arutyunyan arut at nginx.com
Fri Jun 7 15:47:42 UTC 2024


# HG changeset patch
# User Roman Arutyunyan <arut at nginx.com>
# Date 1717774411 -14400
#      Fri Jun 07 19:33:31 2024 +0400
# Node ID e2f6f5d01ff6f0dd2e3f0c9328e794af52e65881
# Parent  02e9411009b987f408214ab4a8b6b6093f843bcd
Stream: removed empty input buffer after peek preread.

Since peek preread was introduced in cf890df37bb6 (1.25.5), an empty input
buffer was prepended to client input by ngx_stream_proxy_module after peek
preread, since c->buffer was empty.  An empty c->buffer indicates an empty
datagram for SOCK_DGRAM (see d127837c714f), but has no effect on SOCK_STREAM
connections.  The change eliminates it for SOCK_STREAM.

diff --git a/src/stream/ngx_stream_proxy_module.c b/src/stream/ngx_stream_proxy_module.c
--- a/src/stream/ngx_stream_proxy_module.c
+++ b/src/stream/ngx_stream_proxy_module.c
@@ -863,7 +863,9 @@ ngx_stream_proxy_init_upstream(ngx_strea
         u->upstream_buf.last = p;
     }
 
-    if (c->buffer && c->buffer->pos <= c->buffer->last) {
+    if (c->buffer
+        && (c->buffer->pos < c->buffer->last || c->type == SOCK_DGRAM))
+    {
         ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0,
                        "stream proxy add preread buffer: %uz",
                        c->buffer->last - c->buffer->pos);


More information about the nginx-devel mailing list