From e3c37fc292e0cb5f75809d732b878c8920c9a679 Mon Sep 17 00:00:00 2001 From: Alex Rousskov Date: Wed, 15 Jun 2016 09:37:44 -0600 Subject: [PATCH] Do not make bogus recvmsg(2) calls when closing UDS sockets. comm_empty_os_read_buffers() assumes that all non-blocking FD_READ_METHODs can read into an opaque buffer filled with random characters. That assumption is wrong for UDS sockets that require an initialized msghdr structure. Feeding random data to recvmsg(2) leads to confusing errors, at best. Squid does not log those errors, but they are visible in, for example, strace: recvmsg(17, 0x7fffbb, MSG_DONTWAIT) = -1 EMSGSIZE (Message too long) comm_empty_os_read_buffers() is meant to prevent TCP RST packets. The function now ignores UDS sockets that are not used for TCP. TODO: Useless reads may also exist for UDP and some TCP sockets. --- src/comm.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/comm.cc b/src/comm.cc index b6ecf05d5b..4ca20ffac0 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -110,7 +110,7 @@ comm_empty_os_read_buffers(int fd) /* prevent those nasty RST packets */ char buf[SQUID_TCP_SO_RCVBUF]; - if (fd_table[fd].flags.nonblocking) { + if (fd_table[fd].flags.nonblocking && fd_table[fd].type != FD_MSGHDR) { while (FD_READ_METHOD(fd, buf, SQUID_TCP_SO_RCVBUF) > 0) {}; } #endif -- 2.39.5