{"record":{"id":"cfdcd24b68172b4f","repo":"elastic/elasticsearch","slug":"could-not-connect-to-systemd-socket","errorCode":null,"errorMessage":"Could not connect to systemd socket: {}","messagePattern":"Could not connect to systemd socket: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"libs/native/src/main/java/org/elasticsearch/nativeaccess/Systemd.java","lineNumber":114,"sourceCode":"                    if (error != null) {\n                        error.addSuppressed(e);\n                        throw error;\n                    } else {\n                        throw e;\n                    }\n                }\n            } else if (error != null) {\n                throw error;\n            }\n        }\n    }\n\n    private void throwOrLog(String message, boolean warnOnError) {\n        if (warnOnError) {\n            logger.warn(message);\n        } else {\n            logger.error(message);\n            throw new RuntimeException(message);\n        }\n    }\n}\n","sourceCodeStart":96,"sourceCodeEnd":118,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/native/src/main/java/org/elasticsearch/nativeaccess/Systemd.java#L96-L118","documentation":"Thrown (or logged as a warning) when connect() fails on the Unix datagram socket pointing to the NOTIFY_SOCKET path. For notify_ready() this is a RuntimeException; for other notifications it is a WARN. The socket path may not exist, may be unreachable, or the process may lack permission to connect.","triggerScenarios":"Calling systemd.notify_ready() when NOTIFY_SOCKET points to a path that does not exist (e.g., stale env var after systemd restart), or when the socket is in a different mount namespace (common in containers).","commonSituations":"NOTIFY_SOCKET set from a parent process whose systemd instance has since restarted. Running in a pod/container where the socket path is not mounted. NOTIFY_SOCKET path truncated or malformed. Socket deleted by systemd after service stop.","solutions":["Verify the NOTIFY_SOCKET path exists: 'ls -la $NOTIFY_SOCKET'.","If the path is stale, unset NOTIFY_SOCKET or restart under systemd properly.","In containers, ensure the NOTIFY_SOCKET abstract socket or path is shared with the host systemd.","For abstract sockets (starting with @), verify the namespace is accessible."],"exampleFix":"// before\nsystemd.notify_ready(); // may throw if socket path is stale\n\n// after: validate socket path before notifying\nString sock = System.getenv(\"NOTIFY_SOCKET\");\nif (sock != null && !sock.isEmpty()) {\n    try {\n        systemd.notify_ready();\n    } catch (RuntimeException e) {\n        logger.warn(\"Cannot reach systemd at {}\", sock, e);\n    }\n}","handlingStrategy":"try-catch","validationCode":"String sock = System.getenv(\"NOTIFY_SOCKET\");\nboolean socketReachable = sock != null && !sock.isEmpty()\n    && (sock.startsWith(\"@\") || java.nio.file.Files.exists(java.nio.file.Paths.get(sock)));\nif (!socketReachable) {\n    logger.debug(\"NOTIFY_SOCKET [{}] not reachable, skipping sd_notify\", sock);\n    return;\n}","typeGuard":null,"tryCatchPattern":"try {\n    systemd.notify_ready();\n} catch (RuntimeException e) {\n    logger.warn(\"Failed to connect to systemd NOTIFY_SOCKET; continuing without sd_notify\", e);\n}","preventionTips":["Validate NOTIFY_SOCKET path existence before calling notify_ready().","Do not set NOTIFY_SOCKET manually unless systemd is actually listening.","In Kubernetes, use the proper sd_notify wrapper sidecar rather than a raw env var."],"tags":["systemd","linux","native","socket","connect"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}