{"record":{"id":"3e83914b51f31d5a","repo":"crossbeam-rs/crossbeam","slug":"queue-capacity-is-too-large","errorCode":null,"errorMessage":"queue capacity is too large","messagePattern":"queue capacity is too large","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crossbeam-queue/src/array_queue.rs","lineNumber":133,"sourceCode":"        let tail = 0;\n\n        // Allocate a buffer of `cap` slots initialized\n        // with stamps.\n        let buffer: Box<[Slot<T>]> = (0..cap)\n            .map(|i| {\n                // Set the stamp to `{ lap: 0, index: i }`.\n                Slot {\n                    stamp: AtomicIndex::new(i as Index),\n                    value: UnsafeCell::new(MaybeUninit::uninit()),\n                }\n            })\n            .collect();\n\n        // One lap is the smallest power of two greater than `cap`.\n        let one_lap = (cap as Index)\n            .checked_add(1)\n            .and_then(Index::checked_next_power_of_two)\n            .expect(\"queue capacity is too large\");\n\n        Self {\n            buffer,\n            one_lap,\n            head: CachePadded::new(AtomicIndex::new(head)),\n            tail: CachePadded::new(AtomicIndex::new(tail)),\n        }\n    }\n\n    fn push_or_else<F>(&self, mut value: T, f: F) -> Result<(), T>\n    where\n        F: Fn(T, Index, Index, &Slot<T>) -> Result<T, T>,\n    {\n        let backoff = Backoff::new();\n        let mut tail = self.tail.load(Ordering::Relaxed);\n\n        loop {\n            // Deconstruct the tail.","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/crossbeam-rs/crossbeam/blob/38dacb462261fcd64edcb308aed9cbf95c8c82c3/crossbeam-queue/src/array_queue.rs#L115-L151","documentation":"`ArrayQueue::new(cap)` packs head/tail lap counters into an index word; `cap + 1` rounded up to the next power of two defines one lap and must fit in the `Index` type. When that computation overflows, the queue cannot represent the requested capacity, so `new` panics with this message.","triggerScenarios":"Calling `ArrayQueue::new(cap)` with a capacity so large that `(cap + 1).next_power_of_two()` overflows the internal index integer type.","commonSituations":"Sizing a queue from a total workload or byte count without clamping; passing usize::MAX to mean 'effectively unbounded'; 32-bit builds receiving capacities tuned for 64-bit machines.","solutions":["Pass a smaller capacity that fits the index type","Clamp user/config-provided capacities to a sane maximum before `ArrayQueue::new`","For effectively unbounded needs, use `SegQueue` (crossbeam-queue's unbounded queue) instead"],"exampleFix":"// before\nlet q = ArrayQueue::new(num_items_usize_from_file_size); // may panic\n\n// after\nconst MAX: usize = 1 << 30;\nlet q = ArrayQueue::new(cap.min(MAX).max(1));","handlingStrategy":"validation","validationCode":"const MAX_Q_CAP: usize = 1 << 30;\nif cap == 0 || cap > MAX_Q_CAP { cap = MAX_Q_CAP; }\nlet q = ArrayQueue::new(cap);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sanitize capacities parsed from user input or files","Use SegQueue when the capacity is unknown or huge","Add a startup assertion for capacity ranges on 32-bit targets"],"tags":["rust","crossbeam-queue","panic","capacity","overflow"],"backgroundTag":"value-out-of-range","analyzedSha":"38dacb462261fcd64edcb308aed9cbf95c8c82c3","analyzedAt":"2026-09-13T03:24:01.537Z","contentChangedAt":"2026-09-13T03:24:01.537Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}