From 47aa0bf40382d11a1b641ab1edef6a0d49a9be20 Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Wed, 17 Jul 2024 18:32:24 +0200 Subject: [PATCH] fix: backoff base & factor See https://github.com/srijs/rust-tokio-retry/issues/22 . --- src/client.rs | 6 +++++- src/file_output.rs | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index bcfa057..6f16913 100644 --- a/src/client.rs +++ b/src/client.rs @@ -254,7 +254,11 @@ where F: Fn() -> Fut + Send, Fut: Future> + Send, { - let strategy = tokio_retry::strategy::ExponentialBackoff::from_millis(500) + // WARNING: The exponential config is somewhat weird. `from_millis(base).factor(factor)` means + // `base^retry * factor`. + // Also see https://github.com/srijs/rust-tokio-retry/issues/22 . + let strategy = tokio_retry::strategy::ExponentialBackoff::from_millis(2) + .factor(500) .map(tokio_retry::strategy::jitter); let condition = |e: &reqwest::Error| { diff --git a/src/file_output.rs b/src/file_output.rs index fa8f2d4..11f9c55 100644 --- a/src/file_output.rs +++ b/src/file_output.rs @@ -25,7 +25,12 @@ pub(crate) async fn write_to_file(content: &[u8], path: &Path) -> Result<()> { async fn rename(old: &Path, new: &Path) -> Result<(), std::io::Error> { // some file systems like SMB may not sync immediately and return "not found" shortly after file // creation - let strategy = tokio_retry::strategy::ExponentialBackoff::from_millis(500) + + // WARNING: The exponential config is somewhat weird. `from_millis(base).factor(factor)` means + // `base^retry * factor`. + // Also see https://github.com/srijs/rust-tokio-retry/issues/22 . + let strategy = tokio_retry::strategy::ExponentialBackoff::from_millis(2) + .factor(500) .map(tokio_retry::strategy::jitter) .take(10);