{"record":{"id":"7fcec0198a571097","repo":"libnyanpasu/clash-nyanpasu","slug":"can-t-create-listener-7fcec0","errorCode":null,"errorMessage":"Can't create listener","messagePattern":"Can't create listener","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri-plugin-deep-link/src/windows.rs","lineNumber":98,"sourceCode":"        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}\");\n                                continue;\n                            }\n                            buf.pop();\n                            let current_pid = std::process::id();\n                            let response = format!(\"{current_pid}\\n\");\n                            if let Err(e) = tx.write_all(response.as_bytes()).await {\n                                log::error!(\"Error writing to connection: {e}\");\n                                continue;\n                            }","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri-plugin-deep-link/src/windows.rs#L80-L116","documentation":"After building the tokio listener with ListenerOptions::name(name).security_descriptor(sd).create_tokio(), the result is unwrapped with expect(\"Can't create listener\"). create_tokio fails if the local socket name is invalid or already in use, or if the security descriptor is rejected — typically a leftover listener from a crashed previous instance of the same identifier.","triggerScenarios":"Stale named pipe / local socket still registered by a previously crashed instance; two app instances with the same identifier racing to create the listener; invalid socket name derived from the identifier (bad characters/length).","commonSituations":"App crash leaving the Windows local-socket name occupied; running multiple dev builds simultaneously; identifiers with characters that map poorly to namespaced socket names.","solutions":["Ensure the previous instance fully exited (kill orphaned processes) and retry","Allow only one running instance per identifier","Simplify/normalize the identifier used in prepare() (ASCII, short, no special chars) to get a valid socket name","On bind failure, log the OS error and retry once after a short delay instead of panicking"],"exampleFix":"// before\n.prepare(identifier) // identifier: \"My App (Dev) 2024!!\"\n// after\n.prepare(\"com.example.myapp-dev\") // safe name for socket derivation","handlingStrategy":"fallback","validationCode":"// ensure no other instance owns the local socket name before listening\nassert_single_instance(); // e.g. named-mutex or existing single-instance plugin","typeGuard":null,"tryCatchPattern":"match listener_opts.create_tokio() {\n    Ok(l) => serve(l),\n    Err(e) => { log::error!(\"listener create failed: {e}\"); /* degrade: skip deep-link IPC, notify user */ }\n}","preventionTips":["Guarantee single-instance operation per identifier","Use simple ASCII identifiers so derived socket names are valid","Handle create_tokio errors gracefully instead of panicking; log and continue without deep-link IPC"],"tags":["rust","windows","named-pipe","deep-link","bind"],"backgroundTag":"address-already-in-use","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"}