]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-master: Add 5 second timeout when waiting for stats-writer handshake
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 11 Mar 2020 12:36:10 +0000 (14:36 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 30 Dec 2020 08:57:03 +0000 (08:57 +0000)
Previously the wait was infinite and nothing was logged, making it difficult
to know that the problem is with a hanging stats process.

src/lib-master/stats-client.c

index 0e95ab0b78c4af95355ae02a6be02823a996b921..ae0976f3a4cfc45fd45b83844ae68d384e94f293 100644 (file)
@@ -10,6 +10,7 @@
 #include "connection.h"
 #include "stats-client.h"
 
+#define STATS_CLIENT_TIMEOUT_MSECS (5*1000)
 #define STATS_CLIENT_RECONNECT_INTERVAL_MSECS (10*1000)
 
 struct stats_client {
@@ -286,13 +287,21 @@ static void stats_global_deinit(void)
        connection_list_deinit(&stats_clients);
 }
 
+static void stats_client_timeout(struct stats_client *client)
+{
+       e_error(client->conn.event, "Timeout waiting for handshake response");
+       io_loop_stop(client->ioloop);
+}
+
 static void stats_client_wait_handshake(struct stats_client *client)
 {
        struct ioloop *prev_ioloop = current_ioloop;
+       struct timeout *to;
 
        i_assert(client->to_reconnect == NULL);
 
        client->ioloop = io_loop_create();
+       to = timeout_add(STATS_CLIENT_TIMEOUT_MSECS, stats_client_timeout, client);
        connection_switch_ioloop(&client->conn);
        io_loop_run(client->ioloop);
        io_loop_set_current(prev_ioloop);
@@ -300,6 +309,7 @@ static void stats_client_wait_handshake(struct stats_client *client)
        if (client->to_reconnect != NULL)
                client->to_reconnect = io_loop_move_timeout(&client->to_reconnect);
        io_loop_set_current(client->ioloop);
+       timeout_remove(&to);
        io_loop_destroy(&client->ioloop);
 }