From cc9326c93650f5e853fe02922ddb476af70ce303 Mon Sep 17 00:00:00 2001 From: Arjun Roy Date: Fri, 14 May 2021 13:41:30 -0700 Subject: [PATCH] Correctly reset msg_controllen before processing TCP error queue. (#26250) When we call recvmsg(), we are allowed to set msg_control and msg_controllen to receive ancillary messages from the TCP socket. msg_controllen is set to available buffer length for such sockets before we call recvmsg(); after the call returns successfully, it contains the amount of available data in the ancillary buffer. Existing behaviour is buggy; it calls recvmsg() in a loop but does not set msg_controllen to the size of the full buffer correctly on each iteration. This leads to a surfeit of error log messages, claiming the ancillary messages had to be truncated due to insufficient buffer space. This patch correctly sets the ancillary buffer size before each call to recvmsg() when processing the TCP error queue. --- src/core/lib/iomgr/tcp_posix.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index 1f28b773da9..1bf2dcb2b38 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -1164,9 +1164,9 @@ static bool process_errors(grpc_tcp* tcp) { struct cmsghdr align; } aligned_buf; msg.msg_control = aligned_buf.rbuf; - msg.msg_controllen = sizeof(aligned_buf.rbuf); int r, saved_errno; while (true) { + msg.msg_controllen = sizeof(aligned_buf.rbuf); do { r = recvmsg(tcp->fd, &msg, MSG_ERRQUEUE); saved_errno = errno;