elastic/elasticsearch · warning · RuntimeException

Could not connect to systemd socket: {}

Error message

Could not connect to systemd socket: {}

What it means

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.

Source

Thrown at libs/native/src/main/java/org/elasticsearch/nativeaccess/Systemd.java:114

                    if (error != null) {
                        error.addSuppressed(e);
                        throw error;
                    } else {
                        throw e;
                    }
                }
            } else if (error != null) {
                throw error;
            }
        }
    }

    private void throwOrLog(String message, boolean warnOnError) {
        if (warnOnError) {
            logger.warn(message);
        } else {
            logger.error(message);
            throw new RuntimeException(message);
        }
    }
}

View on GitHub (pinned to db6a809a66)

Solutions

  1. Verify the NOTIFY_SOCKET path exists: 'ls -la $NOTIFY_SOCKET'.
  2. If the path is stale, unset NOTIFY_SOCKET or restart under systemd properly.
  3. In containers, ensure the NOTIFY_SOCKET abstract socket or path is shared with the host systemd.
  4. For abstract sockets (starting with @), verify the namespace is accessible.

Example fix

// before
systemd.notify_ready(); // may throw if socket path is stale

// after: validate socket path before notifying
String sock = System.getenv("NOTIFY_SOCKET");
if (sock != null && !sock.isEmpty()) {
    try {
        systemd.notify_ready();
    } catch (RuntimeException e) {
        logger.warn("Cannot reach systemd at {}", sock, e);
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

String sock = System.getenv("NOTIFY_SOCKET");
boolean socketReachable = sock != null && !sock.isEmpty()
    && (sock.startsWith("@") || java.nio.file.Files.exists(java.nio.file.Paths.get(sock)));
if (!socketReachable) {
    logger.debug("NOTIFY_SOCKET [{}] not reachable, skipping sd_notify", sock);
    return;
}

Try / catch

try {
    systemd.notify_ready();
} catch (RuntimeException e) {
    logger.warn("Failed to connect to systemd NOTIFY_SOCKET; continuing without sd_notify", e);
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/cfdcd24b68172b4f. Report an issue: GitHub.