# HG changeset patch # User Timo Sirainen # Date 1496225468 -10800 # Node ID 81a74bce2b07494f8466acfdd8c0149691e8440e # Parent f65e7542dd4ff1e9360b754cc6828e9e192ca05b director: Fix handshake timeout lengths They weren't too bad, but also they weren't what the #defines described. Also added a separate connect() timeout. diff -r f65e7542dd4f -r 81a74bce2b07 src/director/director-connection.c --- a/src/director/director-connection.c Sat Jun 17 14:39:59 2017 +0300 +++ b/src/director/director-connection.c Wed May 31 13:11:08 2017 +0300 @@ -49,6 +49,8 @@ #define MAX_INBUF_SIZE 1024 #define MAX_OUTBUF_SIZE (1024*1024*10) #define OUTBUF_FLUSH_THRESHOLD (1024*128) +/* Max time to wait for connect() to finish before aborting */ +#define DIRECTOR_CONNECTION_CONNECT_TIMEOUT_MSECS (10*1000) /* Max idling time before "ME" command must have been received, or we'll disconnect. */ #define DIRECTOR_CONNECTION_ME_TIMEOUT_MSECS (10*1000) @@ -428,8 +430,13 @@ } timeout_remove(&conn->to_ping); - conn->to_ping = timeout_add(DIRECTOR_CONNECTION_DONE_TIMEOUT_MSECS, - director_connection_init_timeout, conn); + if (conn->in) { + conn->to_ping = timeout_add(DIRECTOR_CONNECTION_DONE_TIMEOUT_MSECS, + director_connection_init_timeout, conn); + } else { + conn->to_ping = timeout_add(DIRECTOR_CONNECTION_SEND_USERS_TIMEOUT_MSECS, + director_connection_init_timeout, conn); + } if (!conn->in) return TRUE; @@ -1949,8 +1956,6 @@ conn->input = i_stream_create_fd(conn->fd, MAX_INBUF_SIZE, FALSE); conn->output = o_stream_create_fd(conn->fd, MAX_OUTBUF_SIZE, FALSE); o_stream_set_no_error_handling(conn->output, TRUE); - conn->to_ping = timeout_add(DIRECTOR_CONNECTION_ME_TIMEOUT_MSECS, - director_connection_init_timeout, conn); array_append(&dir->connections, &conn, 1); return conn; } @@ -1976,6 +1981,8 @@ conn->connected = TRUE; conn->name = i_strdup_printf("%s/in", net_ip2addr(ip)); conn->io = io_add(conn->fd, IO_READ, director_connection_input, conn); + conn->to_ping = timeout_add(DIRECTOR_CONNECTION_ME_TIMEOUT_MSECS, + director_connection_init_timeout, conn); director_connection_send_handshake(conn); return conn; @@ -1999,7 +2006,7 @@ conn->io = io_add(conn->fd, IO_READ, director_connection_input, conn); timeout_remove(&conn->to_ping); - conn->to_ping = timeout_add(DIRECTOR_CONNECTION_SEND_USERS_TIMEOUT_MSECS, + conn->to_ping = timeout_add(DIRECTOR_CONNECTION_ME_TIMEOUT_MSECS, director_connection_init_timeout, conn); o_stream_cork(conn->output); @@ -2046,6 +2053,8 @@ director_host_ref(host); conn->io = io_add(conn->fd, IO_WRITE, director_connection_connected, conn); + conn->to_ping = timeout_add(DIRECTOR_CONNECTION_CONNECT_TIMEOUT_MSECS, + director_connection_init_timeout, conn); return conn; }