From: Timo Sirainen Date: Tue, 27 Sep 2022 11:28:38 +0000 (+0300) Subject: doveadm: Fix assert-crash on secondary service_user failures X-Git-Tag: 2.3.20~45 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a1b25a1c000a16f7a1748dadaafa6654785b43b;p=thirdparty%2Fdovecot%2Fcore.git doveadm: Fix assert-crash on secondary service_user failures This mainly affected dsync when imapc authentication failed, but could have also happened with copy and import commands. Fixes: Panic: file lib-event.c: line 506 (event_pop_global): assertion failed: (event == current_global_event) --- diff --git a/src/doveadm/doveadm-mail.c b/src/doveadm/doveadm-mail.c index 574c3b7f34..b085231551 100644 --- a/src/doveadm/doveadm-mail.c +++ b/src/doveadm/doveadm-mail.c @@ -457,19 +457,27 @@ doveadm_mail_next_user(struct doveadm_mail_cmd_context *ctx, return ret; } + /* Create the event outside the active ioloop context, so if run() + switches the ioloop context it won't try to pop out the event_reason + from global events. */ + struct ioloop_context *cur_ctx = + io_loop_get_current_context(current_ioloop); + io_loop_context_deactivate(cur_ctx); struct event_reason *reason = event_reason_begin(event_reason_code_prefix("doveadm", "cmd_", ctx->cmd->name)); + io_loop_context_activate(cur_ctx); + T_BEGIN { if (ctx->v.run(ctx, ctx->cur_mail_user) < 0) { i_assert(ctx->exit_code != 0); } } T_END; mail_user_deinit(&ctx->cur_mail_user); - /* user deinit may still do some work, so finish the reason after it */ - event_reason_end(&reason); - mail_storage_service_user_unref(&ctx->cur_service_user); + /* User deinit may still do some work, so finish the reason after it. + Also, this needs to be after the ioloop context is deactivated. */ + event_reason_end(&reason); return 1; }