mirror of
https://github.com/chatmail/core.git
synced 2026-04-21 15:36:30 +03:00
accounts: retry remove_account multiple times on failure
When removing an account, try 60 times with 1 second sleep in between in case removal of database files fails. This happens on Windows platform sometimes due to a known bug in r2d2 which may result in 30 seconds delay until all connections are closed [1]. [1] https://github.com/sfackler/r2d2/issues/99
This commit is contained in:
@@ -148,9 +148,27 @@ impl Accounts {
|
||||
drop(ctx);
|
||||
|
||||
if let Some(cfg) = self.config.get_account(id).await {
|
||||
fs::remove_dir_all(async_std::path::PathBuf::from(&cfg.dir))
|
||||
.await
|
||||
.context("failed to remove account data")?;
|
||||
// Spend up to 1 minute trying to remove the files.
|
||||
// Files may remain locked up to 30 seconds due to r2d2 bug:
|
||||
// https://github.com/sfackler/r2d2/issues/99
|
||||
let mut counter = 0;
|
||||
loop {
|
||||
counter += 1;
|
||||
|
||||
if let Err(err) = fs::remove_dir_all(async_std::path::PathBuf::from(&cfg.dir))
|
||||
.await
|
||||
.context("failed to remove account data")
|
||||
{
|
||||
if counter > 60 {
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
// Wait 1 second and try again.
|
||||
async_std::task::sleep(std::time::Duration::from_millis(1000)).await;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.config.remove_account(id).await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user