diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fa0338b3..df03616f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - 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 - Make sure, videochat-room-names are always URL-safe #3231 +- Try removing account folder multiple times in case of failure #3229 ### Changes diff --git a/src/accounts.rs b/src/accounts.rs index ee13701f5..0d49da0f2 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -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?;