{"record":{"id":"c65ddc92c260468f","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-create-tokio-runtime","errorCode":null,"errorMessage":"failed to create tokio runtime","messagePattern":"failed to create tokio runtime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri-plugin-deep-link/src/windows.rs","lineNumber":89,"sourceCode":"\nstatic CRASH_COUNT: AtomicU16 = AtomicU16::new(0);\n\npub fn listen<F: FnMut(String) + Send + 'static>(mut handler: F) -> Result<()> {\n    if CRASH_COUNT.load(Ordering::Acquire) > 5 {\n        panic!(\"Local socket too many crashes\");\n    }\n\n    std::thread::spawn(move || {\n        let name = ID\n            .get()\n            .expect(\"listen() called before prepare()\")\n            .as_str()\n            .to_ns_name::<GenericNamespaced>()\n            .unwrap();\n        tokio::runtime::Builder::new_current_thread()\n            .enable_all()\n            .build()\n            .expect(\"failed to create tokio runtime\")\n            .block_on(async move {\n                let sdsf = \"D:(A;;GA;;;WD)\".to_wtf_16().unwrap();\n                let sd = SecurityDescriptor::deserialize(&sdsf).expect(\"Failed to deserialize SD\");\n                let listener = ListenerOptions::new()\n                    .name(name)\n                    .nonblocking(ListenerNonblockingMode::Both)\n                    .security_descriptor(sd)\n                    .create_tokio()\n                    .expect(\"Can't create listener\");\n\n                loop {\n                    match listener.accept().await {\n                        Ok(conn) => {\n                            let (rx, mut tx) = conn.split();\n                            let mut reader = BufReader::new(rx);\n                            let mut buf = String::new();\n                            if let Err(e) = reader.read_line(&mut buf).await {\n                                log::error!(\"Error reading from connection: {e}\");","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri-plugin-deep-link/src/windows.rs#L71-L107","documentation":"listen() spawns a thread that builds a current-thread tokio runtime via Builder::build().expect(). Runtime construction can fail (e.g. when a required IO/driver feature is disabled or resources are unavailable), and the library panics instead of returning an error because it runs on a background thread.","triggerScenarios":"tokio built without the features this listener needs (rt, net, etc.) so enable_all()/build() fails; pathological environments where runtime creation fails (resource exhaustion).","commonSituations":"Dependency conflicts downgrading/disabling tokio features (e.g. another crate enabling default-features = false); minimal builds missing 'net'/'rt' features; running in heavily restricted environments.","solutions":["Ensure the tokio dependency includes features [\"rt\", \"net\", \"macros\"] (or just use default features)","Check for workspace dependency unification stripping tokio features (cargo tree -i tokio)","If the failure persists, restructure to run the listener on an existing tokio runtime instead of building a new one"],"exampleFix":"// before\ntokio = { version = \"1\", default-features = false }\n// after\ntokio = { version = \"1\", features = [\"rt\", \"net\", \"macros\"] }","handlingStrategy":"retry","validationCode":"// ensure tokio features are enabled in Cargo.toml:\n// tokio = { version = \"1\", features = [\"rt\", \"net\", \"macros\"] }\nlet rt = match tokio::runtime::Builder::new_current_thread().enable_all().build() {\n    Ok(rt) => rt,\n    Err(e) => { log::error!(\"tokio runtime: {e}\"); return; }\n};","typeGuard":null,"tryCatchPattern":"let rt = tokio::runtime::Builder::new_current_thread()\n    .enable_all().build()\n    .expect(\"failed to create tokio runtime: check tokio 'rt'/'net' features\");","preventionTips":["Keep tokio default features or explicitly enable rt+net+macros","Run cargo tree -i tokio to detect feature-stripping unification","Avoid default-features = false on tokio without re-adding needed features"],"tags":["rust","windows","tokio","runtime","deep-link"],"backgroundTag":"module-init-failed","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}