client: Set the socket non-blocking only after connect succeeds
authorAmitay Isaacs <amitay@gmail.com>
Mon, 18 Mar 2013 02:45:08 +0000 (13:45 +1100)
committerAmitay Isaacs <amitay@gmail.com>
Fri, 5 Apr 2013 04:20:21 +0000 (15:20 +1100)
If the socket is set non-blocking before connect, then we should catch
EAGAIN errors and retry. Instead of adding a random number of retries,
better to wait for connect to succeed and then set the socket to
non-blocking.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
(cherry picked from commit 524ec206e6a5e8b11723f4d8d1251ed5d84063b0)

client/ctdb_client.c
libctdb/ctdb.c

index 4a02ae56920d63199973419134271472d25dac83..0f0f17566eebe9589dcac58a9eb4d46433ecf083 100644 (file)
@@ -263,9 +263,6 @@ int ctdb_socket_connect(struct ctdb_context *ctdb)
                return -1;
        }
 
-       set_nonblocking(ctdb->daemon.sd);
-       set_close_on_exec(ctdb->daemon.sd);
-       
        if (connect(ctdb->daemon.sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
                close(ctdb->daemon.sd);
                ctdb->daemon.sd = -1;
@@ -273,6 +270,9 @@ int ctdb_socket_connect(struct ctdb_context *ctdb)
                return -1;
        }
 
+       set_nonblocking(ctdb->daemon.sd);
+       set_close_on_exec(ctdb->daemon.sd);
+       
        ctdb->daemon.queue = ctdb_queue_setup(ctdb, ctdb, ctdb->daemon.sd, 
                                              CTDB_DS_ALIGNMENT, 
                                              ctdb_client_read_cb, ctdb, "to-ctdbd");
index 46f49537f86a4d22675f0691de12481cbe3e22db..874654660dc6856a441bbd0d7ccc306193133478 100644 (file)
@@ -176,12 +176,12 @@ struct ctdb_connection *ctdb_connect(const char *addr,
        if (ctdb->fd < 0)
                goto free_fail;
 
-       set_nonblocking(ctdb->fd);
-       set_close_on_exec(ctdb->fd);
-
        if (connect(ctdb->fd, (struct sockaddr *)&sun, sizeof(sun)) == -1)
                goto close_fail;
 
+       set_nonblocking(ctdb->fd);
+       set_close_on_exec(ctdb->fd);
+
        /* Immediately queue a request to get our pnn. */
        if (!ctdb_getpnn_send(ctdb, CTDB_CURRENT_NODE, set_pnn, NULL))
                goto close_fail;