{"record":{"id":"a92dca6e52e338ef","repo":"libnyanpasu/clash-nyanpasu","slug":"can-t-create-listener-a92dca","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/macos.rs","lineNumber":152,"sourceCode":"    }\n\n    unsafe {\n        let event_manager: Retained<AnyObject> =\n            msg_send_id![class!(NSAppleEventManager), sharedAppleEventManager];\n\n        let handler = Handler::new();\n        let handler_boxed = Box::into_raw(Box::new(handler));\n\n        let _: () = msg_send![&event_manager,\n            setEventHandler: &**handler_boxed\n            andSelector: sel!(handleEvent:withReplyEvent:)\n            forEventClass:EVENT_CLASS\n            andEventID:EVENT_GET_URL];\n    }\n\n    #[cfg(debug_assertions)]\n    std::thread::spawn(move || {\n        let listener = UnixListener::bind(addr).expect(\"Can't create listener\");\n\n        for stream in listener.incoming() {\n            match stream {\n                Ok(mut stream) => {\n                    let mut buffer = String::new();\n                    if let Err(io_err) = stream.read_to_string(&mut buffer) {\n                        log::error!(\"Error reading incoming connection: {}\", io_err.to_string());\n                    };\n\n                    let mut cb = HANDLER.get().unwrap().lock().unwrap();\n                    cb(buffer);\n                }\n                Err(err) => {\n                    log::error!(\"Incoming connection failed: {}\", err);\n                    continue;\n                }\n            }\n        }","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri-plugin-deep-link/src/macos.rs#L134-L170","documentation":"In debug builds, listen() spawns a thread that binds a Unix domain socket at /tmp/<id>-deep-link.sock; UnixListener::bind().expect() panics if the bind fails. Typical causes are a stale socket file from a crashed previous instance or a path/permission problem.","triggerScenarios":"Previous instance crashed without removing the socket file (bind fails with EADDRINUSE); another process holds the path; /tmp unwritable or full; two instances of the same identifier racing to bind.","commonSituations":"Debug sessions after an app crash leaving the .sock behind; running multiple copies of the dev app simultaneously; container/sandbox environments where /tmp is restricted.","solutions":["Delete the stale /tmp/<identifier>-deep-link.sock file and restart","Ensure only one instance of the app runs per identifier","Use Linux-style cleanup (remove_file on ConnectionRefused before binding) as done on other platforms","Verify /tmp is writable in your environment"],"exampleFix":"// before\nlet listener = UnixListener::bind(addr).expect(\"Can't create listener\");\n// after\nlet _ = std::fs::remove_file(&addr); // clean stale socket\nlet listener = UnixListener::bind(addr).expect(\"Can't create listener\");","handlingStrategy":"fallback","validationCode":"let addr = format!(\"/tmp/{}-deep-link.sock\", ID.get().expect(\"prepare() first\"));\nif std::path::Path::new(&addr).exists() { let _ = std::fs::remove_file(&addr); }","typeGuard":null,"tryCatchPattern":"match UnixListener::bind(&addr) {\n    Ok(l) => serve(l),\n    Err(e) if e.kind() == std::io::ErrorKind::AddrInUse => {\n        let _ = std::fs::remove_file(&addr);\n        serve(UnixListener::bind(&addr).expect(\"bind after cleanup\"));\n    }\n    Err(e) => panic!(\"bind failed: {e}\"),\n}","preventionTips":["Remove stale socket files before binding (like the linux.rs ConnectionRefused cleanup)","Run only one instance per identifier","Check /tmp permissions in sandboxes/CI"],"tags":["rust","unix-socket","macos","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"}