{"record":{"id":"1ab94c41071c7500","repo":"neondatabase/neon","slug":"resource-multiplier-must-be-between-0-0-and-1-0-ex","errorCode":null,"errorMessage":"resource_multiplier must be between 0.0 and 1.0 exclusive, got {}","messagePattern":"resource_multiplier must be between 0\\.0 and 1\\.0 exclusive, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libs/vm_monitor/src/filecache.rs","lineNumber":76,"sourceCode":"\nimpl Default for FileCacheConfig {\n    fn default() -> Self {\n        Self {\n            resource_multiplier: 0.75,\n            // 256 MiB - lower than when in memory because overcommitting is safe; if we don't have\n            // memory, the kernel will just evict from its page cache, rather than e.g. killing\n            // everything.\n            min_remaining_after_cache: NonZeroU64::new(256 * MiB).unwrap(),\n            spread_factor: 0.1,\n        }\n    }\n}\n\nimpl FileCacheConfig {\n    /// Make sure fields of the config are consistent.\n    pub fn validate(&self) -> anyhow::Result<()> {\n        // Single field validity\n        anyhow::ensure!(\n            0.0 < self.resource_multiplier && self.resource_multiplier < 1.0,\n            \"resource_multiplier must be between 0.0 and 1.0 exclusive, got {}\",\n            self.resource_multiplier\n        );\n        anyhow::ensure!(\n            self.spread_factor >= 0.0,\n            \"spread_factor must be >= 0, got {}\",\n            self.spread_factor\n        );\n\n        // Check that `resource_multiplier` and `spread_factor` are valid w.r.t. each other.\n        //\n        // As shown in `calculate_cache_size`, we have two lines resulting from `resource_multiplier` and\n        // `spread_factor`, respectively. They are:\n        //\n        //                 `total`           `min_remaining_after_cache`\n        //   size = ————————————————————— - —————————————————————————————\n        //           `spread_factor` + 1         `spread_factor` + 1","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/neondatabase/neon/blob/8f60b04da47ffefe0e52bda2440134b42874eb75/libs/vm_monitor/src/filecache.rs#L58-L94","documentation":"FileCacheConfig::validate enforces 0.0 < resource_multiplier < 1.0 strictly: the multiplier is the fraction of total memory the Postgres file cache may consume (default 0.75), and exactly 0 or 1 breaks the cache-sizing math. The check runs before any cache sizing happens.","triggerScenarios":"Constructing FileCacheConfig with resource_multiplier of exactly 0.0 or 1.0, a negative number, or a value > 1, then calling validate() or building FileCacheState with it.","commonSituations":"Tuning vm_monitor file-cache sizing; config code passing a percentage as a raw number (75 instead of 0.75) or a sentinel like 0 meaning 'default'.","solutions":["Set a value strictly inside (0.0, 1.0), e.g. 0.75","If the value is a percentage, divide by 100 before assigning","Call FileCacheConfig::validate() early at startup so config errors surface immediately"],"exampleFix":"// before\nlet config = FileCacheConfig { resource_multiplier: 1.0, ..Default::default() };\nconfig.validate()?; // Err: must be between 0.0 and 1.0 exclusive\n// after\nlet config = FileCacheConfig { resource_multiplier: 0.75, ..Default::default() };\nconfig.validate()?; // Ok","handlingStrategy":"validation","validationCode":"fn valid_resource_multiplier(v: f64) -> bool {\n    v > 0.0 && v < 1.0\n}\n\n// check derived config before constructing/validating FileCacheConfig\nanyhow::ensure!(valid_resource_multiplier(multiplier), \"resource_multiplier must be in (0.0, 1.0), got {multiplier}\");","typeGuard":null,"tryCatchPattern":"if let Err(e) = config.validate() {\n    if e.to_string().contains(\"resource_multiplier\") {\n        // config error: log the offending value and exit(1); do not fall back to defaults silently\n    }\n    return Err(e);\n}","preventionTips":["Call FileCacheConfig::validate() once at startup","Convert percentage inputs with value / 100.0 before assigning","Unit-test config boundaries (0.0, 1.0, values just inside) in CI"],"tags":["rust","config","validation","vm-monitor","file-cache"],"backgroundTag":"config-value-out-of-range","analyzedSha":"8f60b04da47ffefe0e52bda2440134b42874eb75","analyzedAt":"2026-08-16T23:39:28.135Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}