]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: dns: detect the server's shutdown on a partial TCP response
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 18 Nov 2026 13:53:37 +0000 (14:53 +0100)
committerOlivier Houchard <cognet@ci0.org>
Wed, 18 Nov 2026 13:39:03 +0000 (14:39 +0100)
When a DNS response is only partially received over TCP, the session's
I/O handler reads the available data with applet_getblk() and waits for
more. When nothing new is available, the requested length is zero, and
applet_getblk() never reports the shutdown in this case since
applet_may_get() only checks it when more data than available is
requested. If the server closes after sending part of a response, the
session then waits for data that will never come, and queries assigned
to it are lost until it times out, about 20s later.

Let's check for the shutdown when the message is incomplete: the rest
cannot come anymore. This was brought in 3.3 by commit 217da087f
("MEDIUM: dns: Update the dns_session applet to use its own buffers").
It must be backported to 3.3.

src/dns.c

index 49665cf3bc5038c2fe936d483ac6693de0af847b..093e02f709a7975d9e2611cfe75f141eede13936 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -753,6 +753,10 @@ static void dns_session_io_handler(struct appctx *appctx)
                        if (applet_input_data(appctx) + ds->rx_msg.offset < ds->rx_msg.len) {
                                /* message only partially available */
 
+                               /* the rest will never come once the server has shut */
+                               if (se_fl_test(appctx->sedesc, SE_FL_SHW))
+                                       goto error;
+
                                /* read available data */
                                ret = applet_getblk(appctx, ds->rx_msg.area + ds->rx_msg.offset, applet_input_data(appctx), 0);
                                if (ret <= 0) {