]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: connection: set the socket shutdown flags on socket errors
authorWilly Tarreau <w@1wt.eu>
Wed, 4 Dec 2013 22:44:10 +0000 (23:44 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 4 Dec 2013 22:50:36 +0000 (23:50 +0100)
When we get a hard error from a syscall indicating the socket is dead,
it makes sense to set the CO_FL_SOCK_WR_SH and CO_FL_SOCK_RD_SH flags
to indicate that the socket may not be used anymore. It will ease the
error processing in health checks where the state of socket is very
important. We'll also be able to avoid some setsockopt(nolinger) after
an error.

For now, the rest of the code is not impacted because CO_FL_ERROR is
always tested prior to these flags.

src/connection.c
src/proto_tcp.c
src/raw_sock.c
src/stream_interface.c

index 78d28ed331d66af9131c892cba0c87e6a6ecf62b..456d1bd2c33e8205f89ad382f70f33fdb2d5583a 100644 (file)
@@ -438,6 +438,7 @@ int conn_recv_proxy(struct connection *conn, int flag)
 
  recv_abort:
        conn->err_code = CO_ER_PRX_ABORT;
+       conn->flags |= CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
        goto fail;
 
  fail:
@@ -574,6 +575,7 @@ int conn_local_send_proxy(struct connection *conn, unsigned int flag)
                                goto out_wait;
                        if (errno == EINTR)
                                continue;
+                       conn->flags |= CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
                        goto out_error;
                }
        } while (0);
index 21b17715c9a0c6bd7dfa160a3c303e28ddf355b3..a1c69a278d4bf4ff77cd2373ff604143eda68f5b 100644 (file)
@@ -625,7 +625,7 @@ int tcp_connect_probe(struct connection *conn)
         * and disable polling on this FD.
         */
 
-       conn->flags |= CO_FL_ERROR;
+       conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
        __conn_sock_stop_both(conn);
        return 0;
 }
index b9bb8dcb1eaadd6c215376e9072437d48ade8634..ec76604397762f0d8a479bd076da18cbd9e13441 100644 (file)
@@ -85,7 +85,7 @@ int raw_sock_to_pipe(struct connection *conn, struct pipe *pipe, unsigned int co
 
                /* report error on POLL_ERR before connection establishment */
                if ((fdtab[conn->t.sock.fd].ev & FD_POLL_ERR) && (conn->flags & CO_FL_WAIT_L4_CONN)) {
-                       conn->flags |= CO_FL_ERROR;
+                       conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
                        return retval;
                }
        }
@@ -236,7 +236,7 @@ static int raw_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
 
                /* report error on POLL_ERR before connection establishment */
                if ((fdtab[conn->t.sock.fd].ev & FD_POLL_ERR) && (conn->flags & CO_FL_WAIT_L4_CONN)) {
-                       conn->flags |= CO_FL_ERROR;
+                       conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
                        return done;
                }
        }
@@ -284,7 +284,7 @@ static int raw_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
                        break;
                }
                else if (errno != EINTR) {
-                       conn->flags |= CO_FL_ERROR;
+                       conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
                        break;
                }
        }
@@ -305,7 +305,7 @@ static int raw_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
         * an error without checking.
         */
        if (unlikely(fdtab[conn->t.sock.fd].ev & FD_POLL_ERR))
-               conn->flags |= CO_FL_ERROR;
+               conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
        return done;
 }
 
@@ -359,7 +359,7 @@ static int raw_sock_from_buf(struct connection *conn, struct buffer *buf, int fl
                        break;
                }
                else if (errno != EINTR) {
-                       conn->flags |= CO_FL_ERROR;
+                       conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
                        break;
                }
        }
index 702e7b38bcea47a62edb0eb8fe4481c217c1cce2..4600994412b87faeaea5f93b5a7f6a09c897d492 100644 (file)
@@ -472,6 +472,7 @@ int conn_si_send_proxy(struct connection *conn, unsigned int flag)
                                goto out_wait;
                        if (errno == EINTR)
                                continue;
+                       conn->flags |= CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
                        goto out_error;
                }