]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: rawsock: don't take a short kTLS read for the end of data
authorOlivier Houchard <ohouchard@haproxy.com>
Tue, 24 Nov 2026 17:33:04 +0000 (18:33 +0100)
committerOlivier Houchard <cognet@ci0.org>
Wed, 25 Nov 2026 14:04:54 +0000 (15:04 +0100)
When a read returns less than requested, raw_sock_to_buf() considers
the socket buffer empty, and reports a shutdown if the poller already
saw one. But on a kTLS socket recvmsg() returns at most one record, so
the following records are never read when the peer's FIN is already
there. With "ktls on" on a server closing without a close_notify right
after its response, the response is lost and a 502 is returned.

Let's not do this for reads using a control message buffer, which are
only used for kTLS.

This was introduced in 3.3-dev7 by commit 3d685fcb7 ("MINOR: xprt: Add
recvmsg() and sendmsg() parameters to rcv_buf() and snd_buf()."). It
must be backported to 3.3.

src/raw_sock.c

index 08c13ec5486c1ce7c9521a27ab9a291bbfcad701..619ad793eedd93bb0c1fc28c9b7e8f3471ac2133 100644 (file)
@@ -311,7 +311,8 @@ static size_t raw_sock_to_buf(struct connection *conn, void *xprt_ctx, struct bu
                if (ret > 0) {
                        b_add(buf, ret);
                        done += ret;
-                       if (ret < try) {
+                       /* with kTLS a short read is only the end of a record */
+                       if (ret < try && !msg_control) {
                                /* socket buffer exhausted */
                                fd_cant_recv(conn->handle.fd);