From 16e59784c6b14050b67bb2c3f555d9d7035a43a2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 3 Jul 2022 11:39:35 +0530 Subject: [PATCH] handle failures to send data over socket gracefully --- kitty/prewarm.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/kitty/prewarm.py b/kitty/prewarm.py index 4562b1aa7..af23c8ec9 100644 --- a/kitty/prewarm.py +++ b/kitty/prewarm.py @@ -450,12 +450,20 @@ def fork(self, all_non_child_fds: Iterable[int]) -> None: def handle_death(self, status: int) -> None: if hasattr(os, 'waitstatus_to_exitcode'): status = os.waitstatus_to_exitcode(status) - self.conn.sendall(f'{status}'.encode('ascii')) + try: + self.conn.sendall(f'{status}'.encode('ascii')) + except OSError as e: + print_error(f'Failed to send exit status of socket child with error: {e}') self.conn.shutdown(socket.SHUT_RDWR) self.conn.close() - def handle_creation(self) -> None: - self.conn.sendall(f'{self.pid}:'.encode('ascii')) + def handle_creation(self) -> bool: + try: + self.conn.sendall(f'{self.pid}:'.encode('ascii')) + except OSError as e: + print_error(f'Failed to send pid of socket child with error: {e}') + return False + return True def main(stdin_fd: int, stdout_fd: int, notify_child_death_fd: int, unix_socket: socket.socket) -> None: