]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: raw-sock: don't try to send if an error was already reported
authorWilly Tarreau <w@1wt.eu>
Mon, 29 Aug 2022 14:48:14 +0000 (16:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 29 Aug 2022 16:45:27 +0000 (18:45 +0200)
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.

src/raw_sock.c

index b161f90f24a75abb8cdc0aa0d49abe91bacf8569..e172b1d4e57b17220c55a44f80c1b62d80908dea 100644 (file)
@@ -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;