DioxusLabs/dioxus

(Web) Bug in try_get_or_insert

Closed this issue · 0 comments

Panic in package dioxus-isrg, file memory_cache.rs, function try_get_or_insert when incremental rendering is enabled.

let (timestamp, _) = memory_cache.try_get_or_insert(route.to_string(), or_insert)?;

let now = Utc::now();
let elapsed = timestamp.signed_duration_since(now);
let age = elapsed.num_seconds();
// The cache entry is out of date, so we need to remove it.
if let Some(invalidate_after) = self.invalidate_after {
    if elapsed.to_std().unwrap() > invalidate_after { // <------------    PANIC
        tracing::trace!("memory cache out of date");
        memory_cache.pop(route);
        return Ok(None);
    }
}

It panics at elapsed.to_std() because elapsed is negative and to_str() supports only positive numbers.

Steps To Reproduce

Steps to reproduce the behavior:

  • in my environment, it happens always when incremental rendering is enabled.

Expected behavior

It should not panic.

Screenshots

Environment:

  • Dioxus version: 0.6.0 and 0.6.1
  • Rust version: 1.82
  • OS info: Debian Bookworm
  • App platform: Web