Fix: honor send timeout on unix socket connect
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 13 Sep 2016 20:17:04 +0000 (16:17 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 3 Oct 2016 15:48:41 +0000 (11:48 -0400)
Needed if we want to hold the ust_lock() while we connect to the session
daemon without blocking the application forever if the session daemon is
hung on SIGSTOP.

This only triggers if we launchs _many_ applications with a session
daemon SIGSTOP'd (e.g. 1000 in parallel), so we fill the socket queue,
and applications hang there until the session daemon is SIGCONT'd.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/ust-comm.h
liblttng-ust-comm/lttng-ust-comm.c
liblttng-ust/lttng-ust-comm.c

index fb0c0bbc773b854bfc97af19b93a18e5e7c1b914..6a08b306b1b9ade6b44cf722d8b3d26a73281600 100644 (file)
@@ -190,7 +190,8 @@ struct ustcomm_notify_channel_reply {
  */
 
 extern int ustcomm_create_unix_sock(const char *pathname);
-extern int ustcomm_connect_unix_sock(const char *pathname);
+extern int ustcomm_connect_unix_sock(const char *pathname,
+               long timeout);
 extern int ustcomm_accept_unix_sock(int sock);
 extern int ustcomm_listen_unix_sock(int sock);
 extern int ustcomm_close_unix_sock(int sock);
index 129ad8f259aaa3eea7fea766a567c207fd98797e..c01eb9dec37cc3d76b3dc32308c87519f401753c 100644 (file)
@@ -95,7 +95,7 @@ const char *lttng_ust_strerror(int code)
  *
  * Connect to unix socket using the path name.
  */
-int ustcomm_connect_unix_sock(const char *pathname)
+int ustcomm_connect_unix_sock(const char *pathname, long timeout)
 {
        struct sockaddr_un sun;
        int fd, ret;
@@ -110,6 +110,15 @@ int ustcomm_connect_unix_sock(const char *pathname)
                ret = -errno;
                goto error;
        }
+       if (timeout >= 0) {
+               /* Give at least 10ms. */
+               if (timeout < 10)
+                       timeout = 10;
+               ret = ustcomm_setsockopt_snd_timeout(fd, timeout);
+               if (ret < 0) {
+                       WARN("Error setting connect socket send timeout");
+               }
+       }
        ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
        if (ret < 0) {
                PERROR("fcntl");
index 1720bca9cdbbe07f457ee34f22b6e69a5dfd7f2b..dd8822cf13138a22053a7f04c2a143cbde556ad1 100644 (file)
@@ -459,7 +459,7 @@ int setup_local_apps(void)
 }
 
 /*
- * Get notify_sock timeout, in ms.
+ * Get socket timeout, in ms.
  * -1: wait forever. 0: don't wait. >0: timeout, in ms.
  */
 static
@@ -479,12 +479,20 @@ long get_timeout(void)
        return constructor_delay_ms;
 }
 
+/* Timeout for notify socket send and recv. */
 static
 long get_notify_sock_timeout(void)
 {
        return get_timeout();
 }
 
+/* Timeout for connecting to cmd and notify sockets. */
+static
+long get_connect_sock_timeout(void)
+{
+       return get_timeout();
+}
+
 /*
  * Return values: -1: wait forever. 0: don't wait. 1: timeout wait.
  */
@@ -1367,7 +1375,8 @@ restart:
         * first connect registration message.
         */
        /* Connect cmd socket */
-       ret = ustcomm_connect_unix_sock(sock_info->sock_path);
+       ret = ustcomm_connect_unix_sock(sock_info->sock_path,
+               get_connect_sock_timeout());
        if (ret < 0) {
                DBG("Info: sessiond not accepting connections to %s apps socket", sock_info->name);
                prev_connect_failed = 1;
@@ -1423,7 +1432,8 @@ restart:
        ust_unlock();
 
        /* Connect notify socket */
-       ret = ustcomm_connect_unix_sock(sock_info->sock_path);
+       ret = ustcomm_connect_unix_sock(sock_info->sock_path,
+               get_connect_sock_timeout());
        if (ret < 0) {
                DBG("Info: sessiond not accepting connections to %s apps socket", sock_info->name);
                prev_connect_failed = 1;
This page took 0.028165 seconds and 4 git commands to generate.