Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible panic in Delay initialization #79

Open
Robsutar opened this issue Sep 19, 2024 · 1 comment
Open

Possible panic in Delay initialization #79

Robsutar opened this issue Sep 19, 2024 · 1 comment

Comments

@Robsutar
Copy link

Delay::new can panic due Subtracting Duration from Instant on Mac is panic-prone, it can be seen in this action run.

Suggestion: add documentation, similar to the add implementation for Instant:

impl Add<Duration> 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, like this.

@Robsutar
Copy link
Author

Copy of the log of the action run:

thread 'smol-1' panicked at library/std/src/time.rs:417:33:
overflow when adding duration to instant
stack backtrace:
   0: rust_begin_unwind
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:74:14
   2: core::panicking::panic_display
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:264:5
   3: core::option::expect_failed
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/option.rs:2030:5
   4: core::option::Option<T>::expect
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/option.rs:933:21
   5: <std::time::Instant as core::ops::arith::Add<core::time::Duration>>::add
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/time.rs:417:33
   6: futures_timer::native::delay::Delay::new
             at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-timer-3.0.3/src/native/delay.rs:37:27
   7: lyanne::internal::rt::smol::timeout::{{closure}}
             at ./src/internal/rt/smol.rs:41:26
   8: lyanne::server::ServerInternal::pre_read_next_bytes::{{closure}}
             at ./src/server/mod.rs:667:14
   9: lyanne::server::Server::disconnect::{{closure}}
             at ./src/server/mod.rs:1744:89
  10: async_executor::Executor::spawn_inner::{{closure}}
             at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.13.1/src/lib.rs:250:20
  11: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/future/future.rs:123:9
  12: async_task::raw::RawTask<F,T,S,M>::run::{{closure}}
             at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.1/src/raw.rs:550:21
  13: core::ops::function::FnOnce::call_once
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
  14: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panic/unwind_safe.rs:272:9
  15: std::panicking::try::do_call
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:557:40
  16: ___rust_try
  17: std::panicking::try
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:521:19
  18: std::panic::catch_unwind
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panic.rs:350:14
  19: async_task::raw::RawTask<F,T,S,M>::run
             at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.1/src/raw.rs:549:23
  20: async_task::runnable::Runnable<M>::run
             at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.1/src/runnable.rs:781:18
  21: async_executor::State::run::{{closure}}::{{closure}}
             at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.13.1/src/lib.rs:741:21
  22: <futures_lite::future::Or<F1,F2> as core::future::future::Future>::poll
             at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.3.0/src/future.rs:449:33
  23: async_executor::State::run::{{closure}}
             at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.13.1/src/lib.rs:748:32
  24: async_executor::Executor::run::{{closure}}
             at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.13.1/src/lib.rs:344:34
  25: async_io::driver::block_on::{{closure}}
             at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-io-2.3.4/src/driver.rs:199:37
  26: std::thread::local::LocalKey<T>::try_with
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/local.rs:283:12
  27: std::thread::local::LocalKey<T>::with
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/local.rs:260:9
  28: async_io::driver::block_on
             at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-io-2.3.4/src/driver.rs:175:5
  29: smol::spawn::spawn::global::{{closure}}::{{closure}}::{{closure}}
             at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/smol-2.0.2/src/spawn.rs:50:41
  30: std::panicking::try::do_call
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:557:40
  31: ___rust_try
  32: std::panicking::try
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:521:19
  33: std::panic::catch_unwind
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panic.rs:350:14
  34: smol::spawn::spawn::global::{{closure}}::{{closure}}
             at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/smol-2.0.2/src/spawn.rs:50:25
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Error: Process completed with exit code 101.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant