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

Cache::get method sometimes panics due to an integer overflow in quanta::instant::Instant::now #119

Closed
tatsuya6502 opened this issue May 11, 2022 · 8 comments · Fixed by #126
Labels
bug Something isn't working
Milestone

Comments

@tatsuya6502
Copy link
Member

This issue was reported by @BrynCooke on May 10, 2022 UTC via #113 (comment)

The number of times needed to hit this is very low. Sometimes it happens within 10 invocations, sometimes 100.


I have been hitting this issue and am able to reproduce by running an integration test in a loop.

Looks like it is possibly related to this: metrics-rs/quanta#61

The stacktrace is as follows:

2022-05-10T11:16:52.903652Z ERROR integration_tests: panicked at 'attempt to add with overflow', /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/num/mod.rs:834:5


1: std::panicking::rust_panic_with_hook
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:702:17
   2: std::panicking::begin_panic_handler::{{closure}}
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:586:13
   3: std::sys_common::backtrace::__rust_end_short_backtrace
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/sys_common/backtrace.rs:138:18
   4: rust_begin_unwind
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:584:5
   5: core::panicking::panic_fmt
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/panicking.rs:143:14
   6: core::panicking::panic
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/panicking.rs:48:5
   7: core::num::<impl u64>::next_power_of_two
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/num/uint_macros.rs:2188:13
   8: quanta::Calibration::adjust_cal_ratio
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/quanta-0.9.3/src/lib.rs:272:25
   9: quanta::Calibration::calibrate
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/quanta-0.9.3/src/lib.rs:226:13
  10: quanta::Clock::new::{{closure}}
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/quanta-0.9.3/src/lib.rs:307:17
  11: once_cell::sync::OnceCell<T>::get_or_init::{{closure}}
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/once_cell-1.9.0/src/lib.rs:974:57
  12: once_cell::imp::OnceCell<T>::initialize::{{closure}}
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/once_cell-1.9.0/src/imp_std.rs:95:19
  13: once_cell::imp::initialize_inner
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/once_cell-1.9.0/src/imp_std.rs:171:31
  14: once_cell::imp::OnceCell<T>::initialize
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/once_cell-1.9.0/src/imp_std.rs:93:9
  15: once_cell::sync::OnceCell<T>::get_or_try_init
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/once_cell-1.9.0/src/lib.rs:1014:13
  16: once_cell::sync::OnceCell<T>::get_or_init
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/once_cell-1.9.0/src/lib.rs:974:19
  17: quanta::Clock::new
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/quanta-0.9.3/src/lib.rs:305:31
  18: core::ops::function::FnOnce::call_once
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/ops/function.rs:227:5
  19: once_cell::sync::OnceCell<T>::get_or_init::{{closure}}
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/once_cell-1.9.0/src/lib.rs:974:57
  20: once_cell::imp::OnceCell<T>::initialize::{{closure}}
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/once_cell-1.9.0/src/imp_std.rs:95:19
  21: once_cell::imp::initialize_inner
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/once_cell-1.9.0/src/imp_std.rs:171:31
  22: once_cell::imp::OnceCell<T>::initialize
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/once_cell-1.9.0/src/imp_std.rs:93:9
  23: once_cell::sync::OnceCell<T>::get_or_try_init
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/once_cell-1.9.0/src/lib.rs:1014:13
  24: once_cell::sync::OnceCell<T>::get_or_init
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/once_cell-1.9.0/src/lib.rs:974:19
  25: quanta::get_now
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/quanta-0.9.3/src/lib.rs:532:9
  26: quanta::instant::Instant::now
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/quanta-0.9.3/src/instant.rs:25:9
  27: moka::common::time::Instant::now
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/moka-0.8.2/src/common/time.rs:24:17
  28: moka::sync::base_cache::Inner<K,V,S>::current_time_from_expiration_clock
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/moka-0.8.2/src/sync/base_cache.rs:760:13
  29: moka::sync::base_cache::BaseCache<K,V,S>::get_with_hash::{{closure}}
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/moka-0.8.2/src/sync/base_cache.rs:170:23
  30: moka::cht::map::bucket_array_ref::BucketArrayRef<K,V,S>::get_key_value_and_then
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/moka-0.8.2/src/cht/map/bucket_array_ref.rs:48:30
  31: moka::cht::segment::HashMap<K,V,S>::get_key_value_and_then
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/moka-0.8.2/src/cht/segment.rs:306:9
  32: moka::sync::base_cache::Inner<K,V,S>::get_key_value_and_then
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/moka-0.8.2/src/sync/base_cache.rs:630:9
  33: moka::sync::base_cache::BaseCache<K,V,S>::get_with_hash
             at /home/bryn/.asdf/installs/rust/1.60.0/registry/src/github.com-1ecc6299db9ec823/moka-0.8.2/src/sync/base_cache.rs:167:27
  34: moka::sync::cache::Cache<K,V,S>::get

The number of times needed to hit this is very low. Sometimes it happens within 10 invocations, sometimes 100.

@tatsuya6502
Copy link
Member Author

@BrynCooke

Looks like it is possibly related to this: metrics-rs/quanta#61

Yeah. It looks like so. From your stack trace, I see quanta::instant::Instant::now function is causing the panic.

metrics-rs/quanta#61 (comment)

My Lenovo laptop is AMD based, and it happens pretty quickly.

It also occurred once on a CircleCI run.

My colleagues, who have M1 and Intel CPUs have not been able to reproduce.

As a workaround, I am going to add a Cargo feature to Moka to opt-out Quanta.

Also, when I have more time, I will try to reproduce the issue by using AMD based instance at Amazon EC2.

@tatsuya6502 tatsuya6502 modified the milestone: v0.8.2 May 11, 2022
@tatsuya6502 tatsuya6502 added the bug Something isn't working label May 11, 2022
@tatsuya6502 tatsuya6502 added this to the v0.8.3 milestone May 11, 2022
@tatsuya6502
Copy link
Member Author

As a workaround, I am going to add a Cargo feature to Moka to opt-out Quanta.

Memo: I could reuse the codes here: #39

@tatsuya6502
Copy link
Member Author

As a workaround, I am going to add a Cargo feature to Moka to opt-out Quanta.

Working on this workaround via #121. Not quite finished yet.

@tatsuya6502 tatsuya6502 added the blocked Blocked by something label May 14, 2022
@tatsuya6502 tatsuya6502 removed this from the v0.8.3 milestone May 14, 2022
@tatsuya6502
Copy link
Member Author

Hi @BrynCooke,

I have published Moka v0.8.3 to crates.io. Now you can opt out Quanta crate by adding default-features = false to the Moka dependency in your Cargo.toml. For more details, please see this section of the README.

Hope this helps.

I will keep this GH Issue open until Quanta addresses the issue.

@tatsuya6502 tatsuya6502 changed the title Cache::get method sometimes panics in debug build due to an integer overflow in quanta::instant::Instant::now Cache::get method sometimes panics in due to an integer overflow in quanta::instant::Instant::now May 15, 2022
@BrynCooke
Copy link

@tatsuya6502 Thanks for sorting this out so quickly!

@tatsuya6502 tatsuya6502 removed the blocked Blocked by something label May 19, 2022
@tatsuya6502 tatsuya6502 added this to the v0.8.4 milestone May 19, 2022
@tatsuya6502 tatsuya6502 changed the title Cache::get method sometimes panics in due to an integer overflow in quanta::instant::Instant::now Cache::get method sometimes panics due to an integer overflow in quanta::instant::Instant::now May 19, 2022
@tatsuya6502
Copy link
Member Author

Hi @BrynCooke — I have published Moka v0.8.4 to crates.io. It depends on the latest Quanta v0.10.0 that has the fix for the panic issue. Please try Moka v0.8.4 when you have time. Thanks!

@BrynCooke
Copy link

I had a go and can no longer reproduce the issue. Thanks @tatsuya6502!

BrynCooke pushed a commit to apollographql/router that referenced this issue May 24, 2022
Moka has a dependency on Quanta which had an issue with AMD hardware. This is now fixed via [Moka-#119](moka-rs/moka#119).
BrynCooke pushed a commit to apollographql/router that referenced this issue May 24, 2022
Moka has a dependency on Quanta which had an issue with AMD hardware. This is now fixed via [Moka-#119](moka-rs/moka#119).
BrynCooke added a commit to apollographql/router that referenced this issue May 24, 2022
Moka has a dependency on Quanta which had an issue with AMD hardware. This is now fixed via [Moka-#119](moka-rs/moka#119).

Co-authored-by: bryn <bryn@apollographql.com>
BrynCooke pushed a commit to apollographql/router that referenced this issue May 24, 2022
Moka has a dependency on Quanta which had an issue with AMD hardware. This is now fixed via [Moka-#119](moka-rs/moka#119).
@tobz
Copy link

tobz commented May 25, 2022

Glad to hear the issue is fixed. 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants