From 6dee9eae981f3dabef9155b02fd12345d0a8ee40 Mon Sep 17 00:00:00 2001 From: Dominik Sander Date: Tue, 29 Dec 2020 15:33:48 +0100 Subject: [PATCH 1/2] Detect closed connections in `_receive_response` When the connection to the deluge server was lost (the server was restarted or shut down), `_receive_response` was stuck in a infinite loop before. Since `recv` never returns any data the function never broke out of the while loop. Raising a `ConnectionLostException` ensures the retry logic can work as expected. --- deluge_client/client.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/deluge_client/client.py b/deluge_client/client.py index 246da5c..fb313aa 100644 --- a/deluge_client/client.py +++ b/deluge_client/client.py @@ -173,6 +173,9 @@ def _receive_response(self, deluge_version, protocol_version, partial_data=b''): except ssl.SSLError: raise CallTimeoutException() + if len(d) == 0: + raise ConnectionLostException() + data += d if deluge_version == 2: if expected_bytes is None: From eb67b6f1d42e38e4ae26b33a2502f266189d77a0 Mon Sep 17 00:00:00 2001 From: Dominik Sander Date: Tue, 29 Dec 2020 15:37:28 +0100 Subject: [PATCH 2/2] Make the socket timeout configurable --- deluge_client/client.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/deluge_client/client.py b/deluge_client/client.py index fb313aa..574e518 100644 --- a/deluge_client/client.py +++ b/deluge_client/client.py @@ -48,14 +48,13 @@ class RemoteException(DelugeClientException): class DelugeRPCClient(object): - timeout = 20 - - def __init__(self, host, port, username, password, decode_utf8=False, automatic_reconnect=True): + def __init__(self, host, port, username, password, decode_utf8=False, automatic_reconnect=True, timeout=20): self.host = host self.port = port self.username = username self.password = password self.deluge_version = None + self.timeout = timeout # This is only applicable if deluge_version is 2 self.deluge_protocol_version = None