{"record":{"id":"63f2fac8e3aa23c8","repo":"shadowsocks/shadowsocks-rust","slug":"create-tokio-runtime","errorCode":null,"errorMessage":"create tokio Runtime","messagePattern":"create tokio Runtime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/service/local.rs","lineNumber":996,"sourceCode":"            })?;\n        }\n\n        info!(\"shadowsocks local {} build {}\", crate::VERSION, crate::BUILD_TIME);\n\n        let mut builder = match service_config.runtime.mode {\n            RuntimeMode::SingleThread => Builder::new_current_thread(),\n            #[cfg(feature = \"multi-threaded\")]\n            RuntimeMode::MultiThread => {\n                let mut builder = Builder::new_multi_thread();\n                if let Some(worker_threads) = service_config.runtime.worker_count {\n                    builder.worker_threads(worker_threads);\n                }\n\n                builder\n            }\n        };\n\n        let runtime = builder.enable_all().build().expect(\"create tokio Runtime\");\n\n        (config, service_config, runtime)\n    };\n\n    let main_fut = async move {\n        let config_path = config.config_path.clone();\n\n        let instance = Server::new(config).await.expect(\"create local\");\n\n        let reload_task = match config_path {\n            Some(config_path) => ServerReloader {\n                config_path: config_path.clone(),\n                balancer: instance.server_balancer().clone(),\n            }\n            .launch_reload_server_task()\n            .boxed(),\n            None => future::pending().boxed(),\n        };","sourceCodeStart":978,"sourceCodeEnd":1014,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/src/service/local.rs#L978-L1014","documentation":"shadowsocks-rust's `create` builds a tokio multi-thread (or current-thread) Runtime via `builder.enable_all().build().expect(\"create tokio Runtime\")`. The expect panics when tokio cannot construct the runtime, which almost always means the requested worker/thread configuration is invalid or runtime resources (threads) cannot be allocated. This happens before any server work starts, so the process aborts immediately during startup.","triggerScenarios":"Calling `create` (invoked from `main`) with a `--worker-threads` value of 0, or with thread/stack configuration values tokio's Builder rejects; tokio's `Builder::build()` returning Err (e.g. io error spawning threads).","commonSituations":"Users passing `--worker-threads 0` on the command line; containers with extremely low thread limits (ulimit / cgroup pids restriction); exotic platforms where tokio cannot spawn threads.","solutions":["Fix the `--worker-threads` (or equivalent builder config) value — must be >= 1","Remove explicit runtime tuning flags so tokio defaults are used","Check container/cgroup thread and pid limits (ulimit -u, pids.max) and raise them","Upgrade shadowsocks-rust / tokio if running on an unusual platform"],"exampleFix":"// before\nshadowsocks-service --worker-threads 0 ...\n// after\nshadowsocks-service --worker-threads 4 ...","handlingStrategy":"validation","validationCode":"// before launch\nlet workers: usize = std::env::args().collect::<Vec<_>>().join(\" \")\n    .split(\"--worker-threads\")\n    .nth(1).and_then(|s| s.trim().split_whitespace().next())\n    .and_then(|v| v.parse().ok()).unwrap_or(num_cpus::get());\nassert!(workers >= 1, \"--worker-threads must be >= 1\");","typeGuard":"fn valid_workers(n: u64) -> bool { n >= 1 }","tryCatchPattern":"// panic from .expect is not catchable in a meaningful way; validate before launch\nmatch std::panic::catch_unwind(start_service) {\n    Ok(_) => {},\n    Err(_) => eprintln!(\"runtime init failed; check --worker-threads and thread limits\"),\n}","preventionTips":["Never pass --worker-threads 0","Check ulimit -u and cgroup pids.max in containers","Rely on tokio defaults unless profiling shows a need to tune"],"tags":["tokio","runtime","startup","panic"],"backgroundTag":"module-init-failed","analyzedSha":"8eb0f0a65b1d976ab6bed5787327ef86529b0435","analyzedAt":"2026-09-09T12:20:43.168Z","contentChangedAt":"2026-09-09T12:20:43.168Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}