Skip to content

Commit 14795ab

Browse files
ramfox“ramfox”
andauthored
chore: switch from backoff to backon (#3227)
## Description `backoff` is no longer maintained, upgrade path in cargo-deny indicates switching to `backon`. ## Notes & open questions There are some options in `backon` for using sleepers in the retry that are Wasm compatible: https://docs.rs/backon/1.4.0/backon/#sleep I'm curious if we should be taking advantage. Further questions: ~how do I resolve the `paste` cargo-deny issue?~ I don't: added `paste` and `humantime` advisories to the "allow" list ## Change checklist <!-- Remove any that are not relevant. --> - [x] Self-review. --------- Co-authored-by: “ramfox” <“[email protected]”>
1 parent 4930837 commit 14795ab

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

Cargo.lock

Lines changed: 22 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deny.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ allow = [
1919

2020
[advisories]
2121
ignore = [
22-
"RUSTSEC-2024-0384", # unmaintained, no upgrade available
22+
"RUSTSEC-2024-0384", # unmaintained, no upgrade available
23+
"RUSTSEC-2024-0436", # paste
2324
]

iroh/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ aead = { version = "0.5.2", features = ["bytes"] }
2525
anyhow = { version = "1" }
2626
atomic-waker = "1.1.2"
2727
concurrent-queue = "2.5"
28-
backoff = { version = "0.4.0", features = ["futures"] }
28+
backon = { version = "1.4" }
2929
bytes = "1.7"
3030
crypto_box = { version = "0.9.1", features = ["serde", "chacha20"] }
3131
data-encoding = "2.2"

iroh/src/magicsock/relay_actor.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use std::{
3838
};
3939

4040
use anyhow::{anyhow, Result};
41-
use backoff::exponential::{ExponentialBackoff, ExponentialBackoffBuilder};
41+
use backon::{BackoffBuilder, ExponentialBuilder, Retryable};
4242
use bytes::{Bytes, BytesMut};
4343
use iroh_base::{NodeId, PublicKey, RelayUrl, SecretKey};
4444
use iroh_metrics::{inc, inc_by};
@@ -404,9 +404,10 @@ impl ActiveRelayActor {
404404
/// connections. It currently does not ever return `Err` as the retries continue
405405
/// forever.
406406
fn dial_relay(&self) -> BoxFuture<Result<Client>> {
407-
let backoff: ExponentialBackoff<backoff::SystemClock> = ExponentialBackoffBuilder::new()
408-
.with_initial_interval(Duration::from_millis(10))
409-
.with_max_interval(Duration::from_secs(5))
407+
let backoff = ExponentialBuilder::new()
408+
.with_min_delay(Duration::from_millis(10))
409+
.with_max_delay(Duration::from_secs(5))
410+
.without_max_times()
410411
.build();
411412
let connect_fn = {
412413
let client_builder = self.relay_client_builder.clone();
@@ -417,41 +418,31 @@ impl ActiveRelayActor {
417418
Ok(Ok(client)) => Ok(client),
418419
Ok(Err(err)) => {
419420
warn!("Relay connection failed: {err:#}");
420-
Err(err.into())
421+
Err(err)
421422
}
422423
Err(_) => {
423424
warn!(?CONNECT_TIMEOUT, "Timeout connecting to relay");
424-
Err(anyhow!("Timeout").into())
425+
Err(anyhow!("Timeout"))
425426
}
426427
}
427428
}
428429
}
429430
};
430431

431-
// We implement our own `Sleeper` here, so that we can use the `backoff`
432+
// We implement our own `Sleeper` here, so that we can use the `backon`
432433
// crate with our own implementation of `time::sleep` (from `n0_future`)
433434
// that works in browsers.
434435
struct Sleeper;
435436

436-
impl backoff::future::Sleeper for Sleeper {
437+
impl backon::Sleeper for Sleeper {
437438
type Sleep = time::Sleep;
438439

439440
fn sleep(&self, dur: Duration) -> Self::Sleep {
440441
time::sleep(dur)
441442
}
442443
}
443444

444-
// Because we're using a lower-level backoff API, we need to provide a
445-
// backoff::Notify implementation. By default backoff has one that
446-
// doesn't do anything, but it doesn't expose that API. So we implement
447-
// it here ourselves.
448-
struct NoopNotify;
449-
450-
impl<E> backoff::Notify<E> for NoopNotify {
451-
fn notify(&mut self, _: E, _: Duration) {}
452-
}
453-
454-
let retry_fut = backoff::future::Retry::new(Sleeper, backoff, NoopNotify, connect_fn);
445+
let retry_fut = connect_fn.retry(backoff).sleep(Sleeper);
455446
Box::pin(retry_fut)
456447
}
457448

0 commit comments

Comments
 (0)