diff --git a/server.py b/server.py index e9ae8bde..50cece7d 100644 --- a/server.py +++ b/server.py @@ -1127,47 +1127,19 @@ class PromptServer(): await call_on_start() def _get_systemd_sockets(self) -> List[socket.socket]: - """ - Detect systemd socket activation and return a list of ready‑to‑use - ``socket.socket`` objects. - - The function follows the systemd protocol: - * `LISTEN_FDS` tells how many file descriptors have been passed. - * `LISTEN_PID` must match ``os.getpid()``. - * File descriptors start at 3. - * After we have consumed them we *unset* the environment variables so - that any child processes don’t accidentally try to reuse the same - fds. - """ - sockets: List[socket.socket] = [] - + sockets = [] if "LISTEN_FDS" not in os.environ or "LISTEN_PID" not in os.environ: return sockets - - try: - listen_fds = int(os.getenv("LISTEN_FDS", "0")) - listen_pid = int(os.getenv("LISTEN_PID", "0")) - except ValueError: - logging.error("Invalid LISTEN_FDS/LISTEN_PID values") - return sockets - + listen_fds = int(os.getenv("LISTEN_FDS", "0")) + listen_pid = int(os.getenv("LISTEN_PID", "0")) if listen_pid != os.getpid(): - # The activation was meant for a *different* process (e.g. a - # parent that forked before exec). Ignore it. return sockets - for i in range(listen_fds): fd = 3 + i try: - sock = _fd_to_socket(fd) - sockets.append(sock) - logging.debug(f"systemd socket #{i} – fd {fd} – family {sock.family} " - f"type {sock.type} proto {sock.proto}") - except OSError as exc: - logging.error(f"Failed to convert fd {fd} into a socket: {exc}") - - # Remove the activation env‑vars – child processes will otherwise think - # they have been passed sockets as well. + sockets.append(_fd_to_socket(fd)) + except Exception as e: + logging.error(f"Failed to convert fd {fd}: {e}") os.unsetenv("LISTEN_FDS") os.unsetenv("LISTEN_PID") return sockets