{"record":{"id":"5dd4ce598bed35bf","repo":"quickwit-oss/quickwit","slug":"the-right-iterator-should-not-be-empty","errorCode":null,"errorMessage":"The right iterator should not be empty.","messagePattern":"The right iterator should not be empty\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-common/src/sorted_iter.rs","lineNumber":77,"sourceCode":"                    let left = self\n                        .left\n                        .next()\n                        .expect(\"The left iterator should not be empty.\");\n                    Some(Diff::Removed(left))\n                }\n                Ordering::Equal => {\n                    let left = self\n                        .left\n                        .next()\n                        .expect(\"The left iterator should not be empty.\");\n                    self.right.next();\n                    Some(Diff::Unchanged(left))\n                }\n                Ordering::Greater => {\n                    let right = self\n                        .right\n                        .next()\n                        .expect(\"The right iterator should not be empty.\");\n                    Some(Diff::Added(right))\n                }\n            },\n            (Some(_), None) => {\n                let left = self\n                    .left\n                    .next()\n                    .expect(\"The left iterator should not be empty.\");\n                Some(Diff::Removed(left))\n            }\n            (None, Some(_)) => {\n                let right = self\n                    .right\n                    .next()\n                    .expect(\"The right iterator should not be empty.\");\n                Some(Diff::Added(right))\n            }\n            (None, None) => None,","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-common/src/sorted_iter.rs#L59-L95","documentation":"When both iterators peek Some and left key > right key, right.next() must return the peeked element. The expect asserts the right iterator is not empty; failure means the right iterator breaks the Iterator contract or was mutated concurrently.","triggerScenarios":"SortedIterator diff where the right iterator's next() returns None right after peek() returned Some — caused by a misimplemented iterator or concurrent advancement of the right source.","commonSituations":"Custom iterators over live data (e.g. shard lists refreshed mid-iteration); shared iterators advanced from multiple threads; local patches to sorted_iter.rs.","solutions":["Make the right iterator consistent between peek and next","Snapshot the underlying collection before diffing instead of iterating live data","Do not share the iterator across threads without synchronization","Fix any local modifications to quickwit-common::sorted_iter"],"exampleFix":"// before\nlet right = self.right.next().expect(\"The right iterator should not be empty.\");\n// after\nlet right = match self.right.next() { Some(r) => r, None => return None };","handlingStrategy":"type-guard","validationCode":"// Materialize the right sequence before diffing\nlet right: Vec<_> = right_iter.collect();","typeGuard":"fn right_stable<I: Iterator + Clone>(it: &I) -> bool { let mut p = it.clone().peekable(); p.peek().is_some() == p.next().is_some() }","tryCatchPattern":"std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| diff_loop())).unwrap_or_else(|_| eprintln!(\"diff panicked on right iterator\"));","preventionTips":["Never advance the right iterator from another thread while diffing","Use owned, static data for the right side of comparisons","Fix custom iterators that return None right after a Some peek","Keep sorted_iter.rs unmodified upstream"],"tags":["rust","iterator","invariant","peekable"],"backgroundTag":"internal-invariant-violation","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}