Browse Source

Only get new proxy from the second retry onwards

Nick Barrett 2 years ago
parent
commit
df09382580
2 changed files with 11 additions and 7 deletions
  1. 7 5
      mauigpapi/mqtt/conn.py
  2. 4 2
      mautrix_instagram/user.py

+ 7 - 5
mauigpapi/mqtt/conn.py

@@ -566,9 +566,11 @@ class AndroidMQTT:
         finally:
             self.log.debug(f"Dispatcher loop {loop_id} stopped")
 
-    async def update_proxy_and_sleep(self, sleep):
-        if self.proxy_handler and self.proxy_handler.update_proxy_url():
-            self.setup_proxy()
+    async def update_proxy_and_sleep(self, retry):
+        sleep = retry * 2
+        if retry > 1:
+            if self.proxy_handler and self.proxy_handler.update_proxy_url():
+                self.setup_proxy()
             await self._dispatch(ProxyUpdate())
         await self._dispatch(
             Disconnect(reason=f"MQTT Error: no connection, retrying in {sleep} seconds")
@@ -620,7 +622,7 @@ class AndroidMQTT:
                 elif rc == pmc.MQTT_ERR_NO_CONN:
                     if connection_retries > retry_limit:
                         raise MQTTNotConnected(f"Connection failed {connection_retries} times")
-                    await self.update_proxy_and_sleep(sleep=connection_retries * 2)
+                    await self.update_proxy_and_sleep(connection_retries)
                 else:
                     err = pmc.error_string(rc)
                     self.log.error("MQTT Error: %s", err)
@@ -631,7 +633,7 @@ class AndroidMQTT:
                 except MQTTReconnectionError:
                     if connection_retries > retry_limit:
                         raise
-                    await self.update_proxy_and_sleep(sleep=connection_retries * 2)
+                    await self.update_proxy_and_sleep(connection_retries)
 
                 connection_retries += 1
             else:

+ 4 - 2
mautrix_instagram/user.py

@@ -667,7 +667,8 @@ class User(DBUser, BaseUser):
                     f"{e.__class__.__name__} while trying to sync, retrying in {wait} seconds: {e}"
                 )
                 await asyncio.sleep(wait)
-                await self._maybe_update_proxy("sync error")
+                if errors > 1:
+                    await self._maybe_update_proxy("sync error")
             except IGNotLoggedInError as e:
                 self.log.exception("Got not logged in error while syncing")
                 await self.logout(error=e)
@@ -889,7 +890,8 @@ class User(DBUser, BaseUser):
                     f"retrying in {wait} seconds: {e}"
                 )
                 await asyncio.sleep(wait)
-                await self._maybe_update_proxy("fetch_user_and_reconnect error")
+                if errors > 1:
+                    await self._maybe_update_proxy("fetch_user_and_reconnect error")
             except IGNotLoggedInError as e:
                 self.log.warning(f"Failed to reconnect to Instagram: {e}, logging out")
                 await self.logout(error=e)