{"record":{"id":"11d8918a246f98ad","repo":"shadowsocks/shadowsocks-rust","slug":"create-tokio-runtime-11d891","errorCode":null,"errorMessage":"create tokio Runtime","messagePattern":"create tokio Runtime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/service/server.rs","lineNumber":546,"sourceCode":"            })?;\n        }\n\n        info!(\"shadowsocks server {} 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, runtime)\n    };\n\n    let main_fut = async move {\n        let abort_signal = monitor::create_signal_monitor();\n        let server = run_server(config);\n\n        tokio::pin!(abort_signal);\n        tokio::pin!(server);\n\n        match future::select(server, abort_signal).await {\n            // Server future resolved without an error. This should never happen.\n            Either::Left((Ok(..), ..)) => Err(ShadowsocksError::ServerExitUnexpectedly(\n                \"server exited unexpectedly\".to_owned(),\n            )),\n            // Server future resolved with error, which are listener errors in most cases\n            Either::Left((Err(err), ..)) => Err(ShadowsocksError::ServerAborted(format!(\"server aborted with {err}\"))),","sourceCodeStart":528,"sourceCodeEnd":564,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/src/service/server.rs#L528-L564","documentation":"This panic comes from `.expect(\"create tokio Runtime\")` on `tokio::runtime::Builder::enable_all().build()` in src/service/server.rs:546. The tokio Runtime builder only fails when the underlying OS refuses to create required resources (event loop/epoll/kqueue fds, timer fds, or worker thread setup), meaning the process cannot start its async runtime at all.","triggerScenarios":"Calling `builder.enable_all().build()` when the OS denies creation of the runtime's internal resources: process/thread limits hit (RLIMIT_NPROC, cgroup pids.max), file descriptor exhaustion, missing epoll/eventfd support (very restricted containers, old kernels, seccomp filters blocking syscalls).","commonSituations":"Running in hardened Docker/Kubernetes pods with seccomp or low pids limits, CI sandboxes, extremely low `ulimit -n`, containers with stripped /proc or missing syscalls (e.g. running under gVisor with restrictive configs).","solutions":["Raise resource limits: `ulimit -n 65535` and check `ulimit -u`; raise cgroup `pids.max`.","Check container seccomp/AppArmor profiles allow epoll_create1, eventfd2, and clone/fork; relax or use a supported runtime.","Reduce tokio worker threads via `--worker-threads`/TOKIO_WORKER_THREADS or a custom builder if thread creation is the failure.","Verify kernel version supports epoll/timerfd (Linux >= 2.6.25) or run on a standard host.","Patch the code to map the build error into a ShadowsocksError instead of `.expect` for a clean message."],"exampleFix":"// before\nlet runtime = builder.enable_all().build().expect(\"create tokio Runtime\");\n// after\nlet runtime = builder\n    .enable_all()\n    .build()\n    .map_err(|e| ShadowsocksError::InternalError(format!(\"create tokio Runtime: {e}\")))?;","handlingStrategy":"try-catch","validationCode":"// Pre-flight: check fd and thread limits before starting the service\nlet limits = fs::read_to_string(\"/proc/self/limits\").unwrap_or_default();\nassert!(!limits.contains(\"Max open files            0\"), \"fd limit too low for tokio runtime\");","typeGuard":null,"tryCatchPattern":"// If patching: replace expect with error propagation\nmatch builder.enable_all().build() {\n    Ok(rt) => rt,\n    Err(e) => {\n        eprintln!(\"failed to create tokio runtime: {e}; check ulimit -n, ulimit -u, and container seccomp profile\");\n        std::process::exit(1);\n    }\n}","preventionTips":["Set generous ulimits (nofile, nproc) in systemd units and container manifests.","Verify seccomp/AppArmor profiles permit epoll_create1/eventfd2/clone before deploying.","Set TOKIO_WORKER_THREADS to a modest value in constrained environments."],"tags":["tokio","runtime","resource-limits","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"}