async-rs / async-rs/futures-timer

Possible panic in Delay initialization

Open
#79 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
219
Forks
42
PR merge metrics
No merged PRs in 30d

Description

[Delay::new](https://docs.rs/futures-timer/2.0.2/futures_timer/struct.Delay.html#method.new) can panic due [Subtracting Duration from Instant on Mac is panic-prone](https://github.com/rust-lang/rust/issues/100141), it can be seen in [this](https://github.com/Robsutar/lyanne/actions/runs/10940688122/job/30373638095) action run.

Suggestion: add documentation, similar to the [add implementation for Instant](https://doc.rust-lang.org/stable/std/time/struct.Instant.html#method.add):

```rust
impl Add for Instant {
type Output = Instant;

/// # Panics
///
/// This function may panic if the resulting point in time cannot be represented by the
/// underlying data structure. See [`Instant::checked_add`] for a version without panic.
fn add(self, other: Duration) -> Instant {
self.checked_add(other).expect("overflow when adding duration to instant")
}
}
```

And/or add an checked function variant for [Delay::new](https://docs.rs/futures-timer/2.0.2/futures_timer/struct.Delay.html#method.new), like [this](https://doc.rust-lang.org/stable/std/time/struct.Instant.html#method.checked_add).

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Delay::new entry point and compare its duration handling with Rust's Instant::checked_add documentation. Determine whether the issue's accepted scope is documenting the panic, adding a checked constructor, or both; done means the chosen behavior is documented or exposed with platform-specific behavior covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.