{"record":{"id":"eaa8fd43946c4bf9","repo":"linera-io/linera-protocol","slug":"capacity-must-be-0","errorCode":null,"errorMessage":"capacity must be > 0","messagePattern":"capacity must be > 0","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"linera-service/src/node_service.rs","lineNumber":1156,"sourceCode":"/// each insert carries the chain's `next_block_height` at query time.\n/// If a newer block has since been processed, the insert is silently dropped.\nstruct QueryResponseCache {\n    chains: papaya::HashMap<ChainId, StdMutex<PerChainCache>>,\n    /// Chains for which we have registered a notification subscription.\n    subscribed: papaya::HashSet<ChainId>,\n    /// Sender half of the notification channel, used to subscribe new chains lazily.\n    notification_sender: StdMutex<Option<tokio::sync::mpsc::UnboundedSender<Notification>>>,\n    capacity_per_chain: std::num::NonZeroUsize,\n}\n\nimpl QueryResponseCache {\n    fn new(capacity_per_chain: usize) -> Self {\n        Self {\n            chains: papaya::HashMap::new(),\n            subscribed: papaya::HashSet::new(),\n            notification_sender: StdMutex::new(None),\n            capacity_per_chain: std::num::NonZeroUsize::new(capacity_per_chain)\n                .expect(\"capacity must be > 0\"),\n        }\n    }\n\n    /// Stores the notification sender (called once during startup).\n    fn set_notification_sender(&self, sender: tokio::sync::mpsc::UnboundedSender<Notification>) {\n        *self\n            .notification_sender\n            .lock()\n            .expect(\"sender mutex poisoned\") = Some(sender);\n    }\n\n    /// Returns the notification sender, if set.\n    fn notification_sender(&self) -> Option<tokio::sync::mpsc::UnboundedSender<Notification>> {\n        self.notification_sender\n            .lock()\n            .expect(\"sender mutex poisoned\")\n            .clone()\n    }","sourceCodeStart":1138,"sourceCodeEnd":1174,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-service/src/node_service.rs#L1138-L1174","documentation":"QueryResponseCache::new wraps its per-chain LRU capacity in NonZeroUsize::new(capacity_per_chain).expect(\"capacity must be > 0\"). A zero capacity is rejected because the underlying LRU (and the cache design) cannot function with zero slots. The value comes from the `linera service` --query-cache-size CLI argument (node_service.rs:1379), so passing 0 panics during service construction at startup.","triggerScenarios":"Starting `linera service --query-cache-size 0` (or a config/script that sets the cache size to zero to 'disable' caching): NonZeroUsize::new(0) returns None and the expect aborts before the service starts listening.","commonSituations":"Operators trying to disable the query cache by setting its size to 0 (the flag is Option<usize>; disabling is done by omitting it); YAML/JSON-to-CLI translation scripts defaulting unset numeric values to 0; tuning scripts that compute size from a metric which can evaluate to 0.","solutions":["Omit --query-cache-size entirely if you want no cache — the None default skips cache creation","Otherwise pass a positive value, e.g. --query-cache-size 100 (the values used in tests)","Fix wrapper scripts that coerce 'disabled'/'null' to 0 before invoking the CLI","If size comes from a computed value, clamp it: max(1, computed)"],"exampleFix":"# before\nlinera service --query-cache-size 0   # panics at startup\n\n# after (disable caching)\nlinera service\n# after (keep cache)\nlinera service --query-cache-size 100","handlingStrategy":"validation","validationCode":"# Never pass 0; omit the flag to disable the cache.\nCACHE_ARGS=()\nif [ -n \"$QUERY_CACHE_SIZE\" ] && [ \"$QUERY_CACHE_SIZE\" != '0' ]; then\n  CACHE_ARGS=(--query-cache-size \"$QUERY_CACHE_SIZE\")\nfi\nlinera service \"${CACHE_ARGS[@]}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat 'disabled' as omitting the flag, not as 0","Clamp computed sizes: SIZE=$(( SIZE > 0 ? SIZE : 1 )) or drop the flag","Smoke-start the service with the final flag set in CI before deploying"],"tags":["linera","cli","service","lru-cache","nonzero","invalid-argument"],"backgroundTag":"zero-capacity-argument","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}