If we get an error on UDP receive, either in udp_peek_addr() or udp_sock_recv(), we'll print an error message. However, this could be a perfectly routine UDP error triggered by an ICMP, which need not go to the error log. This doesn't usually happen, because before receiving we typically clear the error queue from udp_sock_errs(). However, it's possible an error could be flagged after udp_sock_errs() but before we receive. So it's better to handle this error "silently" (trace level only). We'll bail out of the receive, return to the epoll loop, and get an EPOLLERR where we'll handle and report the error properly. In particular there's one situation that can trigger this case much more easily. If we start a new outbound UDP flow to a local destination with nothing listening, we'll get a more or less immediate connection refused error. So, we'll get that error on the very first receive after the connect(). That will occur in udp_flow_defer() -> udp_flush_flow() -> udp_sock_fwd() -> udp_peek_addr() -> recvmsg(). This path doesn't call udp_sock_errs() first, so isn't (imperfectly) protected the way we are most of the time. Fixes: 84ab1305faba ("udp: Polish udp_vu_sock_info() and remove from...") Fixes: 69e5393c3722 ("udp: Move some more of sock_handler tasks into...") Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- udp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/udp.c b/udp.c index f5fb98c2..154f99b5 100644 --- a/udp.c +++ b/udp.c @@ -619,8 +619,8 @@ static int udp_peek_addr(int s, union sockaddr_inany *src, rc = recvmsg(s, &msg, MSG_PEEK | MSG_DONTWAIT); if (rc < 0) { - if (errno != EAGAIN && errno != EWOULDBLOCK) - warn_perror("Error peeking at socket address"); + trace("Error peeking at socket address: %s", strerror_(errno)); + /* Bail out and let the EPOLLERR handler deal with it */ return rc; } @@ -664,7 +664,8 @@ static int udp_sock_recv(const struct ctx *c, int s, struct mmsghdr *mmh, int n) n = recvmmsg(s, mmh, n, 0, NULL); if (n < 0) { - err_perror("Error receiving datagrams"); + trace("Error receiving datagrams: %s", strerror_(errno)); + /* Bail out and let the EPOLLERR handler deal with it */ return 0; } -- 2.49.0