From 3ff91f589ad0119709d17ead3187425b4289cf8d Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Mon, 2 Dec 2024 23:26:45 +0200 Subject: [PATCH] Catch OSError for getsockopt --- bittensor/utils/networking.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bittensor/utils/networking.py b/bittensor/utils/networking.py index 21a9f1be7..a17f40b68 100644 --- a/bittensor/utils/networking.py +++ b/bittensor/utils/networking.py @@ -168,10 +168,11 @@ def ensure_connected(func): def is_connected(substrate) -> bool: """Check if the substrate connection is active.""" sock = substrate.websocket.socket - return ( - sock is not None - and sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) == 0 - ) + try: + sock_opt = sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) + return sock is not None and sock_opt == 0 + except OSError: + return False @retry( exceptions=ConnectionRefusedError,