From a5db002f0015a4a6e70abd45e3c6ff20db593ed2 Mon Sep 17 00:00:00 2001 From: Christian Vanderwall Date: Mon, 31 Mar 2025 14:58:38 -0700 Subject: [PATCH] Fix issue with closing session (#200) I was getting the following error after calling Session.close(): ``` Exception in thread session-packet-receiver: Traceback (most recent call last): File "librespot-python/librespot/crypto.py", line 58, in receive_encoded header_bytes = self.__receive_cipher.decrypt(connection.read(3)) ~~~~~~~~~~~~~~~^^^ File "librespot-python/librespot/core.py", line 1889, in read return self.__socket.recv(length) ~~~~~~~~~~~~~~~~~~^^^^^^^^ OSError: [Errno 9] Bad file descriptor ``` Adding `OSError` to the try/except in `CipherPair.receive_encoded` fixes this issue, making `CipherPair` raise a `RuntimeError` instead, which is properly handled by `Receiver`. --- librespot/crypto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/librespot/crypto.py b/librespot/crypto.py index 6ae8c23..d09a4d5 100644 --- a/librespot/crypto.py +++ b/librespot/crypto.py @@ -65,7 +65,7 @@ class CipherPair: if mac != expected_mac: raise RuntimeError() return Packet(cmd, payload_bytes) - except IndexError: + except (IndexError, OSError): raise RuntimeError("Failed to receive packet")