{"record":{"id":"35035b8dc986474d","repo":"pola-rs/polars","slug":"invalid-value-for-polars-max-concurrent-scans-x","errorCode":null,"errorMessage":"invalid value for POLARS_MAX_CONCURRENT_SCANS: {x}","messagePattern":"invalid value for POLARS_MAX_CONCURRENT_SCANS: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-stream/src/nodes/io_sources/multi_scan/functions/mod.rs","lineNumber":46,"sourceCode":"\n    let max_files_with_slice = match pre_slice {\n        // Calculate the max number of files assuming 1 row per file.\n        Some(v @ Slice::Positive { .. }) => v.end_position().max(1),\n        Some(Slice::Negative { .. }) | None => usize::MAX,\n    };\n\n    // Set this generously high, there are users who scan 10,000's of small files from the cloud.\n    num_pipelines\n        .saturating_add(3)\n        .min(max_files_with_slice)\n        .min(num_sources)\n        .clamp(1, 128)\n}\n\npub fn calc_max_concurrent_scans(num_pipelines: usize, num_sources: usize) -> usize {\n    if let Ok(v) = std::env::var(\"POLARS_MAX_CONCURRENT_SCANS\").map(|x| {\n        x.parse::<NonZeroUsize>()\n            .unwrap_or_else(|_| panic!(\"invalid value for POLARS_MAX_CONCURRENT_SCANS: {x}\"))\n            .get()\n    }) {\n        return v;\n    }\n\n    num_pipelines.min(num_sources).clamp(1, 128)\n}\n\npub async fn is_compressed_source(\n    scan_source: ScanSource,\n    cloud_options: Option<Arc<CloudOptions>>,\n    io_metrics: Option<Arc<IOMetrics>>,\n) -> PolarsResult<bool> {\n    let byte_source_builder = if scan_source.is_cloud_url() || polars_config::config().force_async()\n    {\n        DynByteSourceBuilder::ObjectStore(FetchConfig::legacy())\n    } else {\n        DynByteSourceBuilder::Mmap","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-stream/src/nodes/io_sources/multi_scan/functions/mod.rs#L28-L64","documentation":"Polars panics when POLARS_MAX_CONCURRENT_SCANS is set but not parseable as a non-zero usize. calc_max_concurrent_scans uses it to override the default limit of concurrent scans, which is otherwise min(num_pipelines, num_sources).clamp(1, 128).","triggerScenarios":"Running a multi-file streaming scan with the variable set to '', '0', '1.5', '128 scans', or any non-numeric / out-of-range value.","commonSituations":"Ops teams exporting the value with units or decimals from a capacity-planning doc; empty values in Helm/env manifests.","solutions":["Set the variable to a plain positive integer (1-128 is the sane range).","Unset it to use the automatic clamp of min(num_pipelines, num_sources) to [1, 128].","Validate with a quick shell check: case \"$POLARS_MAX_CONCURRENT_SCANS\" in ''|*[!0-9]*) unset ...;; esac or equivalent."],"exampleFix":"// before\nPOLARS_MAX_CONCURRENT_SCANS=1.5\n// after\nPOLARS_MAX_CONCURRENT_SCANS=32","handlingStrategy":"validation","validationCode":"const v = process.env.POLARS_MAX_CONCURRENT_SCANS;\nif (v !== undefined && (!/^\\d+$/.test(v.trim()) || parseInt(v, 10) === 0 || parseInt(v, 10) > 128)) {\n  throw new Error(`POLARS_MAX_CONCURRENT_SCANS must be an integer in 1..=128, got: '${v}'`);\n}","typeGuard":"function isValidConcurrentScans(v) { const n = Number(v); return v === undefined || (Number.isInteger(n) && n >= 1 && n <= 128); }","tryCatchPattern":"try {\n  runMultiFileScan();\n} catch (e) {\n  if (String(e).includes('POLARS_MAX_CONCURRENT_SCANS')) {\n    delete process.env.POLARS_MAX_CONCURRENT_SCANS;\n    runMultiFileScan();\n  } else throw e;\n}","preventionTips":["Values above 128 get clamped by the default path — stick to 1..128 integers.","No decimals or unit suffixes; parse target is usize.","Review Helm/K8s env blocks for malformed numeric overrides."],"tags":["rust","env-var","concurrency","config"],"backgroundTag":"invalid-env-var-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}