{"record":{"id":"f4a278e0515006c4","repo":"libnyanpasu/clash-nyanpasu","slug":"can-t-create-listener","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/linux.rs","lineNumber":110,"sourceCode":"                \"Couldn't get file name of current executable.\",\n            ))?\n            .to_string_lossy()\n    ));\n\n    remove_file(&target)?;\n    target.pop();\n\n    Ok(())\n}\n\npub fn listen<F: FnMut(String) + Send + 'static>(mut handler: F) -> Result<()> {\n    std::thread::spawn(move || {\n        let addr = format!(\n            \"/tmp/{}-deep-link.sock\",\n            ID.get().expect(\"listen() called before prepare()\")\n        );\n\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                    handler(dbg!(buffer));\n                }\n                Err(err) => {\n                    log::error!(\"Incoming connection failed: {}\", err);\n                    continue;\n                }\n            }\n        }\n    });","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri-plugin-deep-link/src/linux.rs#L92-L128","documentation":"listen() binds a Unix domain socket at /tmp/{app-id}-deep-link.sock and .expects the bind to succeed, panicking with \"Can't create listener\" on failure. Bind fails when the path is invalid, a stale socket file exists without cleanup in a way that blocks bind, the tmp directory is unwritable, or another process owns the socket.","triggerScenarios":"UnixListener::bind fails because another instance of the app already holds the deep-link socket, /tmp is not writable, a leftover socket file with wrong permissions exists at the path, or the app ID contains characters that make the path invalid/too long.","commonSituations":"Running a second instance of the app while the first is still alive; containers/sandboxes with read-only or restricted /tmp; crashes that left a stale socket file; very long app IDs exceeding the 108-byte Unix socket path limit.","solutions":["Ensure only one app instance runs, or forward deep-link URLs to the existing instance instead of binding again.","Delete the stale /tmp/{app-id}-deep-link.sock file before starting if the previous run crashed.","Check /tmp permissions (writable by the app user) and sandbox/container mount settings.","Shorten the app ID if the socket path exceeds ~108 characters.","Patch the plugin to handle bind errors gracefully (return Err / retry with cleanup) instead of expect."],"exampleFix":"// before: blind bind that panics on stale socket\nlet listener = UnixListener::bind(&addr).expect(\"Can't create listener\");\n\n// after: clean up stale socket, then bind\nlet _ = std::fs::remove_file(&addr); // ignore Not-Found\nlet listener = UnixListener::bind(&addr).expect(\"Can't create listener\");","handlingStrategy":"validation","validationCode":"let addr = format!(\"/tmp/{}-deep-link.sock\", APP_ID);\nlet _ = std::fs::remove_file(&addr); // clear stale socket\nassert!(addr.len() <= 107, \"socket path too long\");","typeGuard":null,"tryCatchPattern":"match UnixListener::bind(&addr) { Ok(l) => ..., Err(e) if e.kind() == io::ErrorKind::AddrInUse => eprintln!(\"another instance running\"), Err(e) => return Err(e.into()) }","preventionTips":["Enforce single-instance; forward URLs to the running instance.","Remove stale socket files at startup.","Verify /tmp is writable in your sandbox/container.","Keep the app ID short enough for the 108-byte Unix socket path limit."],"tags":["unix-socket","bind-failure","deep-link","linux","panic"],"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"}