]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: dsync: Switch ioloop for input/output streams while making TCP connection.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Mon, 29 Jan 2018 18:10:38 +0000 (19:10 +0100)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 8 Feb 2018 10:04:01 +0000 (12:04 +0200)
This task is performed in a sub-ioloop, and when returning from that ioloop, the
output stream would sometimes still have an object on the sub-ioloop that was
just destroyed.

src/doveadm/doveadm-dsync.c

index d3d7a69cf5c931470a6e1d08837a37f4ecfbbe91..65ec0b0a405713c571e3e8b812d10f2bed16ea26 100644 (file)
@@ -113,6 +113,14 @@ struct dsync_cmd_context {
 
 static bool legacy_dsync = FALSE;
 
+static void dsync_cmd_switch_ioloop(struct dsync_cmd_context *ctx)
+{
+       if (ctx->input != NULL)
+               i_stream_switch_ioloop(ctx->input);
+       if (ctx->output != NULL)
+               o_stream_switch_ioloop(ctx->output);
+}
+
 static void remote_error_input(struct dsync_cmd_context *ctx)
 {
        const unsigned char *data;
@@ -799,7 +807,7 @@ dsync_connect_tcp(struct dsync_cmd_context *ctx,
 {
        struct doveadm_server *server;
        struct server_connection *conn;
-       struct ioloop *ioloop;
+       struct ioloop *prev_ioloop, *ioloop;
        string_t *cmd;
        const char *error;
 
@@ -816,7 +824,9 @@ dsync_connect_tcp(struct dsync_cmd_context *ctx,
        p_array_init(&server->connections, ctx->ctx.pool, 1);
        p_array_init(&server->queue, ctx->ctx.pool, 1);
 
+       prev_ioloop = current_ioloop;
        ioloop = io_loop_create();
+       dsync_cmd_switch_ioloop(ctx);
 
        if (doveadm_verbose_proctitle) {
                process_title_set(t_strdup_printf(
@@ -852,6 +862,10 @@ dsync_connect_tcp(struct dsync_cmd_context *ctx,
 
        if (array_count(&server->connections) > 0)
                server_connection_destroy(&conn);
+
+       io_loop_set_current(prev_ioloop);
+       dsync_cmd_switch_ioloop(ctx);
+       io_loop_set_current(ioloop);
        io_loop_destroy(&ioloop);
 
        if (ctx->error != NULL) {