fix: do not run more than one housekeeping at a time

With multiple transports there are multiple inbox loops on the same profile `Context`. 
They tend to start running housekeeping at the same time, e.g. when deleting
a message with an attachment, and then `remove_unused_files()`
tries to remove the same files that are already deleted by another thread
and logs errors.
This commit is contained in:
link2xt
2026-03-06 08:49:03 +00:00
committed by l
parent 1e20055523
commit cce8e3bc5a
2 changed files with 8 additions and 0 deletions

View File

@@ -828,6 +828,10 @@ async fn incremental_vacuum(context: &Context) -> Result<()> {
/// Cleanup the account to restore some storage and optimize the database.
pub async fn housekeeping(context: &Context) -> Result<()> {
let Ok(_housekeeping_lock) = context.housekeeping_mutex.try_lock() else {
// Housekeeping is already running in another thread, do nothing.
return Ok(());
};
// Setting `Config::LastHousekeeping` at the beginning avoids endless loops when things do not
// work out for whatever reason or are interrupted by the OS.
if let Err(e) = context