]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap, pop3: Don't autoexpunge if Dovecot is shutting down or process is killed
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 19 Feb 2026 12:33:13 +0000 (14:33 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Sat, 21 Feb 2026 22:46:31 +0000 (22:46 +0000)
This avoids load spikes.

src/imap/imap-client.c
src/pop3/pop3-client.c

index d68a8cab2139ee9fcf6cb84ee0836ea32fdd85fc..8884e8b179a28ea2e6b4bb96d2dbed67890b3a4e 100644 (file)
@@ -547,10 +547,19 @@ static void client_default_destroy(struct client *client, const char *reason)
 
           Don't autoexpunge if the client is hibernated - it shouldn't be any
           different from the non-hibernating IDLE case. For frequent
-          hibernations it could also be doing unnecessarily much work. */
+          hibernations it could also be doing unnecessarily much work.
+
+          Don't perform autoexpunging if whole Dovecot is shutting down. This
+          could lead to a load spike and unnecessarily slowing down the
+          shutdown process. Also don't do this when processes are being
+          killed, for similar reasoning. */
        imap_refresh_proctitle();
        if (!client->hibernated) {
-               client->logout_stats.autoexpunged_count = mail_user_autoexpunge(client->user);
+               if (!master_service_is_killed(master_service) &&
+                   !master_service_is_master_stopped(master_service)) {
+                       client->logout_stats.autoexpunged_count =
+                               mail_user_autoexpunge(client->user);
+               }
                client_log_disconnect(client, reason);
        }
        mail_user_deinit(&client->user);
index 6f93a1bc68cda2de45be4ff53eb208f3aaa913b1..1ad2c5536cccdfe37b06c8d8cf41e4b21efe718e 100644 (file)
@@ -659,9 +659,15 @@ static void client_default_destroy(struct client *client, const char *reason)
           before it starts, and refresh proctitle so it's clear that it's
           doing autoexpunging. We've also sent DISCONNECT to anvil already,
           because this is background work and shouldn't really be counted
-          as an active POP3 session for the user. */
+          as an active POP3 session for the user.
+
+          Don't perform autoexpunging at shutdown to avoid load spikes. See
+          imap code for more detailed reasoning. Although this is less of an
+          issue with POP3 since the sessions are so short-lived. */
        pop3_refresh_proctitle();
-       mail_user_autoexpunge(client->user);
+       if (!master_service_is_killed(master_service) &&
+           !master_service_is_master_stopped(master_service))
+               mail_user_autoexpunge(client->user);
        mail_user_deinit(&client->user);
        settings_free(client->set);
        settings_free(client->mail_set);