{"record":{"id":"e97708ae530a5ec5","repo":"pola-rs/polars","slug":"invalid-value-for-polars-inflight-sink-morsel-limi","errorCode":null,"errorMessage":"invalid value for POLARS_INFLIGHT_SINK_MORSEL_LIMIT: {x}","messagePattern":"invalid value for POLARS_INFLIGHT_SINK_MORSEL_LIMIT: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-stream/src/nodes/io_sinks/config.rs","lineNumber":33,"sourceCode":"const DEFAULT_PARTITIONED_UPLOAD_CHUNK_SIZE: NonZeroUsize =\n    NonZeroUsize::new(6 * 1024 * 1024).unwrap();\n\npub struct IOSinkNodeConfig {\n    pub file_format: FileWriteFormat,\n    pub target: IOSinkTarget,\n    pub unified_sink_args: UnifiedSinkArgs,\n    pub input_schema: SchemaRef,\n}\n\nimpl IOSinkNodeConfig {\n    pub fn num_pipelines_per_sink(&self, num_pipelines: NonZeroUsize) -> NonZeroUsize {\n        NonZeroUsize::min(num_pipelines, self.inflight_morsel_limit(num_pipelines))\n    }\n\n    pub fn inflight_morsel_limit(&self, num_pipelines: NonZeroUsize) -> NonZeroUsize {\n        if let Ok(v) = std::env::var(\"POLARS_INFLIGHT_SINK_MORSEL_LIMIT\").map(|x| {\n            x.parse::<NonZeroUsize>().unwrap_or_else(|_| {\n                panic!(\"invalid value for POLARS_INFLIGHT_SINK_MORSEL_LIMIT: {x}\")\n            })\n        }) {\n            return v;\n        };\n\n        NonZeroUsize::saturating_add(\n            num_pipelines,\n            // Additional buffer to accommodate head-of-line blocking\n            4,\n        )\n    }\n\n    pub fn max_open_sinks(&self) -> NonZeroUsize {\n        if let Ok(v) = std::env::var(\"POLARS_MAX_OPEN_SINKS\").map(|x| {\n            x.parse::<NonZeroUsize>()\n                .unwrap_or_else(|_| panic!(\"invalid value for POLARS_MAX_OPEN_SINKS: {x}\"))\n        }) {\n            return v;","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-stream/src/nodes/io_sinks/config.rs#L15-L51","documentation":"Polars reads the environment variable POLARS_INFLIGHT_SINK_MORSEL_LIMIT to override how many morsels may be in flight per sink pipeline. If the variable is set but cannot be parsed as a non-zero usize, the library panics immediately rather than silently ignoring the bad value.","triggerScenarios":"Setting POLARS_INFLIGHT_SINK_MORSEL_LIMIT to anything not a positive integer (e.g. '0', 'abc', '10.5', empty string) and then running a streaming query with a sink (sink_parquet/csv etc.), which calls inflight_morsel_limit via num_pipelines_per_sink or sink pipeline startup.","commonSituations":"Hand-edited shell profiles or CI/exported env tuning knobs with typos; copy-pasted values with units ('100m', '5k'); setting '0' which NonZeroUsize rejects.","solutions":["Set POLARS_INFLIGHT_SINK_MORSEL_LIMIT to a positive integer, e.g. export POLARS_INFLIGHT_SINK_MORSEL_LIMIT=64.","Unset the variable entirely (unset POLARS_INFLIGHT_SINK_MORSEL_LIMIT) to use the computed default.","Check for empty string or whitespace values in your environment (empty string still fails parse)."],"exampleFix":"# before\nexport POLARS_INFLIGHT_SINK_MORSEL_LIMIT=0\n# after\nexport POLARS_INFLIGHT_SINK_MORSEL_LIMIT=64","handlingStrategy":"validation","validationCode":"import os\nv = os.environ.get(\"POLARS_INFLIGHT_SINK_MORSEL_LIMIT\")\nif v is not None:\n    assert v.isdigit() and int(v) > 0, f\"POLARS_INFLIGHT_SINK_MORSEL_LIMIT must be a positive integer, got {v!r}\"","typeGuard":"def is_positive_int(s: str) -> bool:\n    return s.isdigit() and int(s) > 0","tryCatchPattern":"// Rust side cannot catch panic; validate env before calling polars:\nlet v = std::env::var(\"POLARS_INFLIGHT_SINK_MORSEL_LIMIT\").unwrap_or_default();\nassert!(v.is_empty() || v.parse::<usize>().map_or(false, |n| n > 0));","preventionTips":["Keep tuning env vars as plain positive integers","Unset rather than zero-ing when you want defaults","Validate all POLARS_* env vars at app startup","Watch for empty-string exports in scripts (export X=$OTHER with OTHER unset)"],"tags":["environment-variable","panic","configuration","streaming"],"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"}