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

panic in Receiver::recv_timeout() #54552

Closed
rob-solana opened this issue Sep 25, 2018 · 0 comments
Closed

panic in Receiver::recv_timeout() #54552

rob-solana opened this issue Sep 25, 2018 · 0 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@rob-solana
Copy link

Receiver::recv_timeout() panics with large values of timeout

I tried this code:

let (s, r) = channel();
r.recv_timeout(Duration::new(std::u64::MAX,0)); // never time out

I expected a blocking receive.

Instead, this happened:

thread 'main' panicked at 'overflow when adding duration to time', libcore/option.rs:989:5

https://play.rust-lang.org/?gist=4880602aa21f718bd8fa7e4826380218&version=stable&mode=debug&edition=2015

Meta

rustc --version --verbose

rustc 1.29.0 (aa3ca1994 2018-09-11)
binary: rustc
commit-hash: aa3ca1994904f2e056679fce1f185db8c7ed2703
commit-date: 2018-09-11
host: x86_64-unknown-linux-gnu
release: 1.29.0
LLVM version: 7.0

Backtrace:

stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:475
   5: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:390
   6: rust_begin_unwind
             at libstd/panicking.rs:325
   7: core::panicking::panic_fmt
             at libcore/panicking.rs:77
   8: core::option::expect_failed
             at libcore/option.rs:989
   9: <std::time::Instant as core::ops::arith::Add<core::time::Duration>>::add
             at /checkout/src/libcore/option.rs:312
             at libstd/sys/unix/time.rs:46
             at libstd/sys/unix/time.rs:297
             at libstd/time.rs:218
  10: <std::sync::mpsc::Receiver<T>>::recv_timeout
             at /checkout/src/libstd/sync/mpsc/mod.rs:1300
  11: playground::main
             at src/main.rs:5
  12: std::rt::lang_start::{{closure}}
             at /checkout/src/libstd/rt.rs:74
  13: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  14: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  15: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  16: std::rt::lang_start
             at /checkout/src/libstd/rt.rs:74
  17: main
  18: __libc_start_main
  19: _start
@Havvy Havvy added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Sep 25, 2018
bors added a commit that referenced this issue Jan 2, 2019
Eliminate Receiver::recv_timeout panic

Fixes #54552.

This panic is because `recv_timeout` uses `Instant::now() + timeout` internally. This possible panic is not mentioned in the documentation for this method.

Very recently we merged (still unstable) support for checked addition (#56490) of `Instant + Duration`, so it's now finally possible to add these together without risking a panic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants