]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: check for connection validation earlier
authorWilly Tarreau <w@1wt.eu>
Fri, 27 Dec 2019 09:54:22 +0000 (10:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 27 Dec 2019 15:38:47 +0000 (16:38 +0100)
In conn_fd_handler() we used to first give a chance to the send()
callback to try to send data and validate the connection at the same
time. But since 1.9 we do not call this callback anymore inline, it's
scheduled. So let's validate the connection ealier so that all other
decisions can be taken based on this confirmation. This may notably
be useful to the xprt_done_cb() to know that the connection was
properly validated.

src/connection.c

index 3f3e99d1234d6cdab3d1e85a5fa2dbe468f2966a..c0aac0aaa03997caf59ebc56cb66fdd70b4222c7 100644 (file)
@@ -60,6 +60,21 @@ void conn_fd_handler(int fd)
 
        flags = conn->flags & ~CO_FL_ERROR; /* ensure to call the wake handler upon error */
 
+       if (unlikely(conn->flags & CO_FL_WAIT_L4_CONN) &&
+           ((fd_send_ready(fd) && fd_send_active(fd)) ||
+            (fd_recv_ready(fd) && fd_recv_active(fd)))) {
+               /* Still waiting for a connection to establish and nothing was
+                * attempted yet to probe the connection. this will clear the
+                * CO_FL_WAIT_L4_CONN flag on success.
+                */
+               if (!conn_fd_check(conn))
+                       goto leave;
+       }
+
+       /* Verify if the connection just established. */
+       if (unlikely(!(conn->flags & (CO_FL_WAIT_L4_CONN | CO_FL_WAIT_L6_CONN | CO_FL_CONNECTED))))
+               conn->flags |= CO_FL_CONNECTED;
+
        /* The connection owner might want to be notified about an end of
         * handshake indicating the connection is ready, before we proceed with
         * any data exchange. The callback may fail and cause the connection to
@@ -86,15 +101,6 @@ void conn_fd_handler(int fd)
                __conn_xprt_stop_send(conn);
        }
 
-       if (unlikely(conn->flags & CO_FL_WAIT_L4_CONN)) {
-               /* still waiting for a connection to establish and nothing was
-                * attempted yet to probe the connection. Then let's retry the
-                * connect().
-                */
-               if (!conn_fd_check(conn))
-                       goto leave;
-       }
-
        /* The data transfer starts here and stops on error and handshakes. Note
         * that we must absolutely test conn->xprt at each step in case it suddenly
         * changes due to a quick unexpected close().
@@ -115,10 +121,6 @@ void conn_fd_handler(int fd)
        }
 
  leave:
-       /* Verify if the connection just established. */
-       if (unlikely(!(conn->flags & (CO_FL_WAIT_L4_CONN | CO_FL_WAIT_L6_CONN | CO_FL_CONNECTED))))
-               conn->flags |= CO_FL_CONNECTED;
-
        /* The connection owner might want to be notified about failures to
         * complete the handshake. The callback may fail and cause the
         * connection to be destroyed, thus we must not use it anymore and