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

Fix: module cache delta overflow #3684

Merged
merged 4 commits into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/wasi/src/bin_factory/module_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,19 @@ impl ModuleCache {
// TODO: should return Result<_, anyhow::Error>
pub fn get_webc(&self, webc: &str, runtime: &dyn WasiRuntime) -> Option<BinaryPackage> {
let name = webc.to_string();
let now = platform_clock_time_get(Snapshot0Clockid::Monotonic, 1_000_000).unwrap() as u128;

// Fast path
{
let cache = self.cache_webc.read().unwrap();
if let Some(data) = cache.get(&name) {
if let Some(when_cached) = data.when_cached.as_ref() {
let delta = now - *when_cached;
/* get the current platform time at this point because of the lock conflict
* now time remains the same and the lock from a differnt thread can cause when_cached to go ahead
* and cause a panic
*/
let now = platform_clock_time_get(Snapshot0Clockid::Monotonic, 1_000_000)
.unwrap() as u128;
let delta = now.saturating_sub(*when_cached); //saturating sub for delta and to prevent panic
if delta <= self.cache_time.as_nanos() {
return Some(data.clone());
}
Expand Down