From: Willy Tarreau Date: Mon, 29 Aug 2022 14:48:14 +0000 (+0200) Subject: MINOR: raw-sock: don't try to send if an error was already reported X-Git-Tag: v2.7-dev5~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c6fc77404e70d62e8b425568c55dc971cbd516d7;p=thirdparty%2Fhaproxy.git MINOR: raw-sock: don't try to send if an error was already reported There's no point trying to send() on a socket on which an error was already reported. This wastes syscalls. Till now it was possible to occasionally see an attempt to sendto() after epoll_wait() had reported EPOLLERR. --- diff --git a/src/raw_sock.c b/src/raw_sock.c index b161f90f24..e172b1d4e5 100644 --- a/src/raw_sock.c +++ b/src/raw_sock.c @@ -360,6 +360,13 @@ static size_t raw_sock_from_buf(struct connection *conn, void *xprt_ctx, const s if (!fd_send_ready(conn->handle.fd)) return 0; + if (unlikely(fdtab[conn->handle.fd].state & FD_POLL_ERR)) { + /* an error was reported on the FD, we can't send anymore */ + conn->flags |= CO_FL_ERROR | CO_FL_SOCK_WR_SH | CO_FL_SOCK_RD_SH; + errno = EPIPE; + return 0; + } + if (conn->flags & CO_FL_SOCK_WR_SH) { /* it's already closed */ conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH;