diff --git a/vm/src/dictdatatype.rs b/vm/src/dictdatatype.rs index 1114fa1ed..2a5f2bf01 100644 --- a/vm/src/dictdatatype.rs +++ b/vm/src/dictdatatype.rs @@ -248,9 +248,13 @@ impl Dict { if let Some(index) = entry_index.index() { // Update existing key if let Some(entry) = inner.entries.get_mut(index) { - let entry = entry - .as_mut() - .expect("The dict was changed since we did lookup."); + let Some(entry) = entry.as_mut() else { + // The dict was changed since we did lookup. Let's try again. + // this is very rare to happen + // (and seems only happen with very high freq gc, and about one time in 10000 iters) + // but still possible + continue; + }; if entry.index == index_index { let removed = std::mem::replace(&mut entry.value, value); // defer dec RC