diff --git a/crates/media/src/exr_planes.rs b/crates/media/src/exr_planes.rs index 9ffb89079..7f00c956b 100644 --- a/crates/media/src/exr_planes.rs +++ b/crates/media/src/exr_planes.rs @@ -529,7 +529,7 @@ impl PlaneStore { } // (a failure of the file as it was before: the file changed since, it is read again) let limit = effectcraft_render::memory::decode_limit_generation(); - if let Some((_, _, why, _)) = e.failed.iter().find(|(of, failed, _, made_at)| Arc::ptr_eq(of, index) && *made_at == limit && asks_at_least(index, want, failed)) { + if let Some((_, _, why, _)) = e.failed.iter().find(|(of, failed, _, made_at)| Arc::ptr_eq(of, index) && (!matches!(why, Refused::TooLarge(_)) || *made_at == limit) && asks_at_least(index, want, failed)) { return Step::Done(Err(why.clone())); } if let Some(flight) = e.flight.clone() { @@ -678,7 +678,8 @@ impl PlaneStore { (fs.index.clone(), fs.want.clone()) }; // (failures of another version of the file no longer apply) - e.failed.retain(|(of, _, _, made_at)| Arc::ptr_eq(of, &index) && *made_at == flight.limit_generation); + // (a refusal for the size counts under the limit it was made under only) + e.failed.retain(|(of, _, old, made_at)| Arc::ptr_eq(of, &index) && (!matches!(old, Refused::TooLarge(_)) || *made_at == flight.limit_generation)); if e.failed.len() >= FAILED_KEPT { e.failed.remove(0); } diff --git a/crates/render/src/memory.rs b/crates/render/src/memory.rs index ae8d02104..d1600551b 100644 --- a/crates/render/src/memory.rs +++ b/crates/render/src/memory.rs @@ -440,8 +440,10 @@ static DECODE_ASKING: Mutex<()> = Mutex::new(()); const DECODE_ASKS: usize = 2; fn store_decode_limit(bytes: usize) { - if DECODE_LIMIT.swap(bytes, Ordering::Relaxed) != bytes { - DECODE_GENERATION.fetch_add(1, Ordering::Relaxed); + // (the limit before its generation, both sequentially consistent: whoever sees the new + // generation sees the new limit) + if DECODE_LIMIT.swap(bytes, Ordering::SeqCst) != bytes { + DECODE_GENERATION.fetch_add(1, Ordering::SeqCst); } } @@ -456,7 +458,7 @@ pub fn set_decode_limit(bytes: Option) { /// Changes whenever [`decode_limit`] gives another answer: a request refused for its size is /// asked again after that. pub fn decode_limit_generation() -> u64 { - DECODE_GENERATION.load(Ordering::Relaxed) + DECODE_GENERATION.load(Ordering::SeqCst) } /// Where [`decode_limit`] reads the limit from while nothing set it: the CLI and the MCP server @@ -475,10 +477,10 @@ pub fn decode_limit(floor: usize, need: usize) -> usize { if need <= floor || cfg!(target_arch = "wasm32") { return floor; } - if DECODE_LIMIT.load(Ordering::Relaxed) == 0 && DECODE_UNANSWERED.load(Ordering::Relaxed) < DECODE_ASKS { + if DECODE_LIMIT.load(Ordering::SeqCst) == 0 { let _asking = DECODE_ASKING.lock().unwrap_or_else(PoisonError::into_inner); - // (another thread may have just read it) - if DECODE_LIMIT.load(Ordering::Relaxed) == 0 { + // (another thread may have just read it, or have used up the asks) + if DECODE_LIMIT.load(Ordering::SeqCst) == 0 && DECODE_UNANSWERED.load(Ordering::Relaxed) < DECODE_ASKS { let source = *DECODE_SOURCE.lock().unwrap_or_else(PoisonError::into_inner); match source.and_then(|read| read()) { Some(bytes) => store_decode_limit(bytes), @@ -488,7 +490,7 @@ pub fn decode_limit(floor: usize, need: usize) -> usize { } } } - floor.max(DECODE_LIMIT.load(Ordering::Relaxed)) + floor.max(DECODE_LIMIT.load(Ordering::SeqCst)) } #[cfg(test)]