Browse Source

backfill loop: refresh after login required or challenge errors

Signed-off-by: Sumner Evans <sumner@beeper.com>
Sumner Evans 2 years ago
parent
commit
a491106dd9
1 changed files with 13 additions and 2 deletions
  1. 13 2
      mautrix_instagram/user.py

+ 13 - 2
mautrix_instagram/user.py

@@ -314,13 +314,24 @@ class User(DBUser, BaseUser):
                 await portal.backfill(self, req)
                 await portal.backfill(self, req)
                 await req.mark_done()
                 await req.mark_done()
             except IGLoginRequiredError as e:
             except IGLoginRequiredError as e:
-                self.log.exception("User is logged out. Stopping backfill requests loop.")
-                return
+                self.log.exception(
+                    "User is logged out. Stopping backfill requests loop and forcing refresh."
+                )
+                await self.refresh(resync=False)
+                break
+            except IGChallengeError as e:
+                self.log.exception(
+                    "User received a challenge. Stopping backfill requests loop and "
+                    "forcing refresh."
+                )
+                await self.refresh(resync=False)
+                break
             except Exception as e:
             except Exception as e:
                 self.log.exception("Failed to backfill portal %s: %s", req.portal_thread_id, e)
                 self.log.exception("Failed to backfill portal %s: %s", req.portal_thread_id, e)
 
 
                 # Don't try again to backfill this portal for a minute.
                 # Don't try again to backfill this portal for a minute.
                 await req.set_cooldown_timeout(60)
                 await req.set_cooldown_timeout(60)
+        self._backfill_loop_task = None
 
 
     async def on_connect(self, evt: Connect) -> None:
     async def on_connect(self, evt: Connect) -> None:
         self.log.debug("Connected to Instagram")
         self.log.debug("Connected to Instagram")