{"record":{"id":"9554c6dbca6ddef7","repo":"risingwavelabs/risingwave","slug":"failed-to-parse-tokio-worker-threads","errorCode":null,"errorMessage":"Failed to parse TOKIO_WORKER_THREADS","messagePattern":"Failed to parse TOKIO_WORKER_THREADS","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utils/runtime/src/lib.rs","lineNumber":95,"sourceCode":"        .install_default()\n        .inspect_err(|e| {\n            tracing::error!(?e, \"Failed to install default crypto provider.\");\n        })\n        .unwrap();\n    risingwave_variables::init_server_start_time();\n\n    // `TOKIO` will be read by tokio. Duplicate `RW` for compatibility.\n    if let Some(worker_threads) = std::env::var_os(\"RW_WORKER_THREADS\") {\n        // safety: single-threaded now.\n        unsafe { std::env::set_var(\"TOKIO_WORKER_THREADS\", worker_threads) };\n    }\n\n    // Set the default number of worker threads to be at least `MIN_WORKER_THREADS`, in production.\n    if !cfg!(debug_assertions) {\n        let worker_threads = match std::env::var(\"TOKIO_WORKER_THREADS\") {\n            Ok(v) => v\n                .parse::<usize>()\n                .expect(\"Failed to parse TOKIO_WORKER_THREADS\"),\n            Err(std::env::VarError::NotPresent) => std::thread::available_parallelism()\n                .expect(\"Failed to get available parallelism\")\n                .get(),\n            Err(_) => panic!(\"Failed to parse TOKIO_WORKER_THREADS\"),\n        };\n        if worker_threads < MIN_WORKER_THREADS {\n            tracing::warn!(\n                \"the default number of worker threads ({worker_threads}) is too small, which may lead to issues, increasing to {MIN_WORKER_THREADS}\"\n            );\n            // safety: single-threaded now.\n            unsafe { std::env::set_var(\"TOKIO_WORKER_THREADS\", MIN_WORKER_THREADS.to_string()) };\n        }\n    }\n\n    if let Ok(enable_deadlock_detection) = std::env::var(\"RW_DEADLOCK_DETECTION\") {\n        let enable_deadlock_detection = enable_deadlock_detection\n            .parse()\n            .expect(\"Failed to parse RW_DEADLOCK_DETECTION\");","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/utils/runtime/src/lib.rs#L77-L113","documentation":"In release builds, `main_okk` reads `TOKIO_WORKER_THREADS` to size the tokio runtime. A value that fails `usize` parsing (or is a non-Unicode env var) aborts with `expect`/`panic!` 'Failed to parse TOKIO_WORKER_THREADS', refusing to start with an invalid runtime configuration.","triggerScenarios":"Exporting `TOKIO_WORKER_THREADS=abc`, `8.0`, `\"\"`, or a value with whitespace/unicode issues before launching compute/meta/frontend/compactor/ctl in release mode.","commonSituations":"Kubernetes YAML quoting mistakes ('8 ' vs '8'), copying values with trailing spaces, scripts interpolating empty strings, or setting the value to 'auto' which tokio's own env var accepts elsewhere but this code parses strictly.","solutions":["Set `TOKIO_WORKER_THREADS` to a plain positive integer (e.g. `8`).","Unset the variable to fall back to available parallelism (subject to MIN_WORKER_THREADS).","Fix deployment manifests/scripts to avoid quoting/whitespace around the value.","Avoid non-numeric placeholders like 'auto' — this code path only accepts usize."],"exampleFix":"// before\nTOKIO_WORKER_THREADS=auto ./risingwave compute\n// after\nTOKIO_WORKER_THREADS=8 ./risingwave compute","handlingStrategy":"validation","validationCode":"if let Ok(v) = std::env::var(\"TOKIO_WORKER_THREADS\") {\n    assert!(v.trim().parse::<usize>().is_ok(), \"TOKIO_WORKER_THREADS must be a positive integer\");\n}","typeGuard":null,"tryCatchPattern":"match std::env::var(\"TOKIO_WORKER_THREADS\") {\n    Ok(v) if v.parse::<usize>().is_err() => eprintln!(\"invalid TOKIO_WORKER_THREADS={v:?}; unset or use an integer\"),\n    _ => {}\n}","preventionTips":["Only set TOKIO_WORKER_THREADS to plain integers.","Strip whitespace/quotes in deployment templating.","In debug builds this is ignored — test release config separately."],"tags":["rust","tokio","env","configuration"],"backgroundTag":"invalid-env-var-value","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}