]> 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)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 12 Mar 2018 07:22:59 +0000 (09:22 +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 ea2eb678466fafe0f41bf11e162560f5afa4b245..3c36be4b1c96e641e78a6eabcea7e369eb12eb6c 100644 (file)
@@ -112,6 +112,15 @@ struct dsync_cmd_context {
 
 static bool legacy_dsync = FALSE;
 
+static void dsync_cmd_switch_ioloop_to(struct dsync_cmd_context *ctx,
+                                      struct ioloop *ioloop)
+{
+       if (ctx->input != NULL)
+               i_stream_switch_ioloop_to(ctx->input, ioloop);
+       if (ctx->output != NULL)
+               o_stream_switch_ioloop_to(ctx->output, ioloop);
+}
+
 static void remote_error_input(struct dsync_cmd_context *ctx)
 {
        const unsigned char *data;
@@ -804,7 +813,7 @@ dsync_connect_tcp(struct dsync_cmd_context *ctx,
        struct doveadm_cmd_context *cctx = ctx->ctx.cctx;
        struct doveadm_server *server;
        struct server_connection *conn;
-       struct ioloop *ioloop;
+       struct ioloop *prev_ioloop, *ioloop;
        string_t *cmd;
        const char *p, *error;
 
@@ -824,7 +833,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_to(ctx, ioloop);
 
        if (doveadm_verbose_proctitle) {
                process_title_set(t_strdup_printf(
@@ -860,6 +871,8 @@ dsync_connect_tcp(struct dsync_cmd_context *ctx,
 
        if (array_count(&server->connections) > 0)
                server_connection_destroy(&conn);
+
+       dsync_cmd_switch_ioloop_to(ctx, prev_ioloop);
        io_loop_destroy(&ioloop);
 
        if (ctx->error != NULL) {