From: Stephan Bosch Date: Mon, 29 Jan 2018 18:10:38 +0000 (+0100) Subject: doveadm: dsync: Switch ioloop for input/output streams while making TCP connection. X-Git-Tag: 2.3.9~2399 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bfa8b471b376f4748be56421b0279a4142237d38;p=thirdparty%2Fdovecot%2Fcore.git doveadm: dsync: Switch ioloop for input/output streams while making TCP connection. 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. --- diff --git a/src/doveadm/doveadm-dsync.c b/src/doveadm/doveadm-dsync.c index 9c73393407..f6a9540091 100644 --- a/src/doveadm/doveadm-dsync.c +++ b/src/doveadm/doveadm-dsync.c @@ -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; @@ -802,7 +811,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; @@ -822,7 +831,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( @@ -858,6 +869,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) {