From 5ca2b1c7620d15273d1349f12f087afd737647af Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 2 Sep 2019 22:52:43 +0100 Subject: [PATCH] Add a watchdog for the inbox thread --- daemon.py | 8 ++++++-- inbox.py | 14 +++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/daemon.py b/daemon.py index 377c70fc..74dfc627 100644 --- a/daemon.py +++ b/daemon.py @@ -47,6 +47,7 @@ from posts import expireCache from inbox import inboxPermittedMessage from inbox import inboxMessageHasParams from inbox import runInboxQueue +from inbox import runInboxQueueWatchdog from inbox import savePostToInboxQueue from inbox import populateReplies from follow import getFollowingFeed @@ -3264,7 +3265,7 @@ class PubServer(BaseHTTPRequestHandler): class PubServerUnitTest(PubServer): protocol_version = 'HTTP/1.0' - + def runDaemon(projectVersion, \ instanceId,clientToServer: bool, \ baseDir: str,domain: str, \ @@ -3377,7 +3378,10 @@ def runDaemon(projectVersion, \ httpd.ocapAlways,maxReplies, \ domainMaxPostsPerDay,accountMaxPostsPerDay, \ allowDeletion,debug,httpd.acceptedCaps),daemon=True) - httpd.thrInboxQueue.start() + httpd.thrWatchdog= \ + threadWithTrace(target=runInboxQueueWatchdog, \ + args=(projectVersion,httpd),daemon=True) + httpd.thrWatchdog.start() if clientToServer: print('Running ActivityPub client on ' + domain + ' port ' + str(proxyPort)) else: diff --git a/inbox.py b/inbox.py index a50e9e1a..308603ef 100644 --- a/inbox.py +++ b/inbox.py @@ -1135,7 +1135,19 @@ def restoreQueueItems(baseDir: str,queue: []) -> None: queue.append(os.path.join(queueDir, qfile)) if len(queue)>0: print('Restored '+str(len(queue))+' inbox queue items') - + +def runInboxQueueWatchdog(projectVersion: str,httpd) -> None: + """This tries to keep the inbox thread running even if it dies + """ + print('Starting inbox queue watchdog') + httpd.thrInboxQueue.start() + while True: + time.sleep(20) + if not httpd.thrInboxQueue.isAlive(): + httpd.thrInboxQueue.kill() + httpd.thrInboxQueue.start() + print('Restarting inbox queue...') + def runInboxQueue(projectVersion: str, \ baseDir: str,httpPrefix: str,sendThreads: [],postLog: [], \ cachedWebfingers: {},personCache: {},queue: [], \