{"record":{"id":"d5bd19613b394ed4","repo":"shadowsocks/shadowsocks-rust","slug":"launch-socket-with-name-doesn-t-exist","errorCode":null,"errorMessage":"launch socket with name \"{}\" doesn't exist","messagePattern":"launch socket with name \"(.+?)\" doesn't exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/shadowsocks-service/src/sys/unix/macos.rs","lineNumber":55,"sourceCode":"                }\n                Some(libc::ESRCH) => {\n                    error!(\"current process is not managed by launchd, error: {}\", err);\n                }\n                Some(libc::EALREADY) => {\n                    error!(\n                        \"activate socket name \\\"{}\\\" has already been activated, error: {}\",\n                        name, err\n                    );\n                }\n                _ => {}\n            }\n\n            return Err(err);\n        }\n    }\n\n    let result = if cnt == 0 {\n        Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\"launch socket with name \\\"{}\\\" doesn't exist\", name),\n        ))\n    } else if cnt > 1 {\n        for idx in 0..cnt {\n            unsafe {\n                let fd = *(fds.add(idx));\n                let _ = libc::close(fd);\n            }\n        }\n\n        Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\n                \"launch socket with name \\\"{}\\\" should be unique, but found {}\",\n                name, cnt\n            ),\n        ))","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/crates/shadowsocks-service/src/sys/unix/macos.rs#L37-L73","documentation":"On macOS launchd socket activation, get_launch_activate_socket looks up a pre-opened socket by name via launch_activate_socket. When launchd reports zero matching sockets (cnt == 0), the function returns InvalidData saying the named launch socket doesn't exist. It is raised from the process environment, not the config file.","triggerScenarios":"Running the service with a Sockets/<Name> key expected in its launchd plist but the daemon was started outside launchd, or the requested socket name doesn't match any key in the plist (LAUNCH_SOCKET_NAME / check-in mismatch).","commonSituations":"Running `./shadowsocks` directly from a terminal instead of via launchctl; plist Sockets dictionary renamed; typo between the code's requested name and the plist key; testing launchd activation without `launchctl load`.","solutions":["Start the service via launchctl with the plist containing a matching Sockets entry (launchctl load / launchctl kickstart)","Ensure the socket name requested matches exactly the key under Sockets in the plist","Fall back to binding the address directly when launchd check-in is unavailable (e.g. non-macOS or manual run)"],"exampleFix":"<!-- before -->\n<key>Sockets</key><dict><key>Listener</key>...</dict> // code requests \"listener\"\n<!-- after -->\n<key>Sockets</key><dict><key>listener</key>...</dict> // names match exactly","handlingStrategy":"fallback","validationCode":"if std::env::var(\"LAUNCH_SOCKET_NAME\").is_err() || std::env::var(\"launchd\").is_err() {\n    // not under launchd check-in; bind directly\n    bind_manually(addr)?;\n}","typeGuard":"fn under_launchd() -> bool { std::env::var_os(\"launchd\").is_some() }","tryCatchPattern":"match get_launch_activate_socket(name) {\n    Err(e) if e.kind() == io::ErrorKind::InvalidData && e.to_string().contains(\"doesn't exist\") => {\n        let listener = TcpListener::bind(addr).await?; // fallback to manual bind\n    }\n    other => other?,\n}","preventionTips":["Always provide a manual-bind fallback for non-launchd environments","Keep socket names in code and plist Sockets keys identical","Test the daemon both via launchctl and directly"],"tags":["macos","launchd","socket-activation"],"backgroundTag":"resource-not-found","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"}