]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: Fix assert-crash on secondary service_user failures
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 27 Sep 2022 11:28:38 +0000 (14:28 +0300)
committerMartti Rannanjärvi <martti.rannanjarvi@open-xchange.com>
Tue, 4 Oct 2022 05:46:59 +0000 (08:46 +0300)
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)

src/doveadm/doveadm-mail.c

index 574c3b7f3453b14c34b5ddc9991771d861ac40dd..b085231551cebd60ae47ac91adcc523256b9cfa5 100644 (file)
@@ -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;
 }