mirror of
https://github.com/chatmail/core.git
synced 2026-05-05 22: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:
@@ -11,6 +11,7 @@
|
|||||||
- Take `delete_device_after` into account when calculating ephemeral loop timeout #3211
|
- Take `delete_device_after` into account when calculating ephemeral loop timeout #3211
|
||||||
- Fix a bug where a blocked contact could send a contact request #3218
|
- Fix a bug where a blocked contact could send a contact request #3218
|
||||||
- Make sure, videochat-room-names are always URL-safe #3231
|
- Make sure, videochat-room-names are always URL-safe #3231
|
||||||
|
- Try removing account folder multiple times in case of failure #3229
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
|
|||||||
@@ -148,9 +148,27 @@ impl Accounts {
|
|||||||
drop(ctx);
|
drop(ctx);
|
||||||
|
|
||||||
if let Some(cfg) = self.config.get_account(id).await {
|
if let Some(cfg) = self.config.get_account(id).await {
|
||||||
fs::remove_dir_all(async_std::path::PathBuf::from(&cfg.dir))
|
// Spend up to 1 minute trying to remove the files.
|
||||||
.await
|
// Files may remain locked up to 30 seconds due to r2d2 bug:
|
||||||
.context("failed to remove account data")?;
|
// 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?;
|
self.config.remove_account(id).await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user