Skip to content

Commit

Permalink
avoid race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
sistemd committed Feb 12, 2024
1 parent 6aadd75 commit 8878a1e
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions crates/executor/src/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ pub fn trace(
let mut receiver = receiver.resubscribe();
drop(cache);

let trace = receiver
.blocking_recv()
.context("Trace error")?;
let trace = receiver.blocking_recv().context("Trace error")?;
return Ok(trace);
}
None => {
Expand Down Expand Up @@ -182,13 +180,10 @@ pub fn trace(
traces.push((hash, trace));
}

// Lock the cache before sending to avoid race conditions between senders and receivers.
let mut cache = cache.0.lock().unwrap();
let _ = sender.send(traces.clone());

cache
.0
.lock()
.unwrap()
.cache_set(block_hash, CacheItem::Cached(traces.clone()));
cache.cache_set(block_hash, CacheItem::Cached(traces.clone()));
Ok(traces)
}

Expand Down

0 comments on commit 8878a1e

Please sign in to comment.