{"record":{"id":"1f60050fb9520db5","repo":"firecracker-microvm/firecracker","slug":"bus-ranges-and-devices-out-of-sync","errorCode":null,"errorMessage":"Bus ranges and devices out of sync","messagePattern":"Bus ranges and devices out of sync","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/vmm/src/vstate/bus.rs","lineNumber":201,"sourceCode":"    // The ranges read lock is only held for resolving the address and is\n    // dropped before performing the operation on the device.\n    fn with_device<T>(\n        &self,\n        addr: u64,\n        f: impl FnOnce(&mut dyn BusDevice, u64, u64) -> T,\n    ) -> Result<T, BusError> {\n        let devices = self.devices.read().unwrap();\n        let (base, slot) = {\n            let ranges = self.ranges.read().unwrap();\n            match ranges.range(..=BusRange::new(addr, 1).unwrap()).next_back() {\n                Some((range, &slot)) if addr <= range.end() => (range.base(), slot),\n                _ => return Err(BusError::MissingAddressRange),\n            }\n        };\n\n        let device = devices\n            .get(slot)\n            .expect(\"Bus ranges and devices out of sync\");\n\n        let Some(device) = device.upgrade() else {\n            return Err(BusError::MissingAddressRange);\n        };\n\n        let mut locked = device.lock().unwrap();\n        let offset = addr - base;\n        Ok(f(&mut *locked, base, offset))\n    }\n\n    /// Relocate an existing device mapping from `old_base` to `new_base`.\n    /// Only the `ranges` lock is taken, not the `devices` lock.\n    pub fn move_range(&self, old_base: u64, new_base: u64, len: u64) -> Result<(), BusError> {\n        let old_range = BusRange::new(old_base, len)?;\n        let new_range = BusRange::new(new_base, len)?;\n\n        let mut ranges = self.ranges.write().unwrap();\n","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/firecracker-microvm/firecracker/blob/0a745def42ddf4cc2a744d79a08a27ff50b5d27a/src/vmm/src/vstate/bus.rs#L183-L219","documentation":"Error \"Bus ranges and devices out of sync\" thrown in firecracker-microvm/firecracker.","triggerScenarios":"Thrown at src/vmm/src/vstate/bus.rs:201 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Keep the bus range list and device list updates in a single atomic operation so they cannot diverge.","Check the bus insert/remove logic for a path that updates one list without the other."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0a745def42ddf4cc2a744d79a08a27ff50b5d27a","analyzedAt":"2026-08-19T05:27:02.517Z","contentChangedAt":"2026-08-19T05:27:02.517Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}