From 2a7f03af8a502077bd4d58c7bc665a5e82d086dc Mon Sep 17 00:00:00 2001 From: shortcutme Date: Sun, 4 Sep 2016 18:00:08 +0200 Subject: [PATCH] Try to reconnect to Tor on send error --- src/Tor/TorManager.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Tor/TorManager.py b/src/Tor/TorManager.py index 465dc469..b01ad794 100644 --- a/src/Tor/TorManager.py +++ b/src/Tor/TorManager.py @@ -232,8 +232,17 @@ class TorManager: if not conn: conn = self.conn self.log.debug("> %s" % cmd) - conn.send("%s\r\n" % cmd) - back = conn.recv(1024 * 64).decode("utf8", "ignore") + for retry in range(2): + try: + conn.send("%s\r\n" % cmd) + back = conn.recv(1024 * 64).decode("utf8", "ignore") + break + except Exception, err: + self.log.error("Tor send error: %s, reconnecting..." % err) + self.disconnect() + time.sleep(1) + self.connect() + back = None self.log.debug("< %s" % back.strip()) return back