mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 00:46:31 +03:00
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:
@@ -239,6 +239,9 @@ pub struct InnerContext {
|
|||||||
pub(crate) oauth2_mutex: Mutex<()>,
|
pub(crate) oauth2_mutex: Mutex<()>,
|
||||||
/// Mutex to prevent a race condition when a "your pw is wrong" warning is sent, resulting in multiple messages being sent.
|
/// Mutex to prevent a race condition when a "your pw is wrong" warning is sent, resulting in multiple messages being sent.
|
||||||
pub(crate) wrong_pw_warning_mutex: Mutex<()>,
|
pub(crate) wrong_pw_warning_mutex: Mutex<()>,
|
||||||
|
/// Mutex to prevent running housekeeping from multiple threads at once.
|
||||||
|
pub(crate) housekeeping_mutex: Mutex<()>,
|
||||||
|
|
||||||
pub(crate) translated_stockstrings: StockStrings,
|
pub(crate) translated_stockstrings: StockStrings,
|
||||||
pub(crate) events: Events,
|
pub(crate) events: Events,
|
||||||
|
|
||||||
@@ -478,6 +481,7 @@ impl Context {
|
|||||||
generating_key_mutex: Mutex::new(()),
|
generating_key_mutex: Mutex::new(()),
|
||||||
oauth2_mutex: Mutex::new(()),
|
oauth2_mutex: Mutex::new(()),
|
||||||
wrong_pw_warning_mutex: Mutex::new(()),
|
wrong_pw_warning_mutex: Mutex::new(()),
|
||||||
|
housekeeping_mutex: Mutex::new(()),
|
||||||
translated_stockstrings: stockstrings,
|
translated_stockstrings: stockstrings,
|
||||||
events,
|
events,
|
||||||
scheduler: SchedulerState::new(),
|
scheduler: SchedulerState::new(),
|
||||||
|
|||||||
@@ -828,6 +828,10 @@ async fn incremental_vacuum(context: &Context) -> Result<()> {
|
|||||||
|
|
||||||
/// Cleanup the account to restore some storage and optimize the database.
|
/// Cleanup the account to restore some storage and optimize the database.
|
||||||
pub async fn housekeeping(context: &Context) -> Result<()> {
|
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
|
// Setting `Config::LastHousekeeping` at the beginning avoids endless loops when things do not
|
||||||
// work out for whatever reason or are interrupted by the OS.
|
// work out for whatever reason or are interrupted by the OS.
|
||||||
if let Err(e) = context
|
if let Err(e) = context
|
||||||
|
|||||||
Reference in New Issue
Block a user