diff --git a/daemon.py b/daemon.py index 15e8c5e09..7de30ca2d 100644 --- a/daemon.py +++ b/daemon.py @@ -790,6 +790,12 @@ class PubServer(BaseHTTPRequestHandler): messageBytes: str) -> int: """Update the inbox queue """ + if self.server.restartInboxQueueInProgress: + self._503() + print('Message arrrived but currently restarting inbox queue') + self.server.POSTbusy = False + return 2 + # check for blocked domains so that they can be rejected early messageDomain = None if messageJson.get('actor'): @@ -810,6 +816,8 @@ class PubServer(BaseHTTPRequestHandler): print('Queue: Inbox queue is full') self._503() self.server.POSTbusy = False + if not restartInboxQueueInProgress: + self.server.restartInboxQueue=True return 2 # Convert the headers needed for signature verification to dict @@ -7258,6 +7266,11 @@ def runDaemon(blogsInstance: bool, mediaInstance: bool, httpd.thrPostSchedule = \ threadWithTrace(target=runPostSchedule, args=(baseDir, httpd, 20), daemon=True) + + # flags used when restarting the inbox queue + httpd.restartInboxQueueInProgress=False + httpd.restartInboxQueue=False + if not unitTest: print('Creating inbox queue watchdog') httpd.thrWatchdog = \ diff --git a/inbox.py b/inbox.py index 430275180..609f20c44 100644 --- a/inbox.py +++ b/inbox.py @@ -2185,11 +2185,15 @@ def runInboxQueueWatchdog(projectVersion: str, httpd) -> None: httpd.thrInboxQueue.start() while True: time.sleep(20) - if not httpd.thrInboxQueue.isAlive(): + if not httpd.thrInboxQueue.isAlive() or httpd.restartInboxQueue: + httpd.restartInboxQueueInProgress=True httpd.thrInboxQueue.kill() httpd.thrInboxQueue = inboxQueueOriginal.clone(runInboxQueue) + httpd.inboxQueue.clear() httpd.thrInboxQueue.start() print('Restarting inbox queue...') + httpd.restartInboxQueueInProgress=False + httpd.restartInboxQueue=False def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,