From 03f647b56d7e5883930e5a9ba3422272b0ae0437 Mon Sep 17 00:00:00 2001 From: Thilo Molitor Date: Fri, 27 Oct 2023 05:50:46 +0200 Subject: [PATCH] Parallelize parse queue freezing, thanks steve This will counter db "deadlocks" where one account is starving another and we try to freeze the starved one first. --- Monal/NotificationService/NotificationService.m | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Monal/NotificationService/NotificationService.m b/Monal/NotificationService/NotificationService.m index 79bab69271..8a753ac8d3 100644 --- a/Monal/NotificationService/NotificationService.m +++ b/Monal/NotificationService/NotificationService.m @@ -357,8 +357,19 @@ -(void) incomingIPC:(NSNotification*) notification -(void) freezeAllParseQueues { DDLogInfo(@"Freezing all incoming streams until we know if we are either terminating or got another push"); + dispatch_queue_t queue = dispatch_queue_create("im.monal.freezeAllParseQueues", DISPATCH_QUEUE_CONCURRENT); for(xmpp* account in [MLXMPPManager sharedInstance].connectedXMPP) - [account freezeParseQueue]; + { + //disconnect to prevent endless loops trying to connect + dispatch_async(queue, ^{ + DDLogVerbose(@"freezeAllParseQueues: %@", account); + [account freezeParseQueue]; + DDLogVerbose(@"freezeAllParseQueues: %@", account); + }); + } + dispatch_barrier_sync(queue, ^{ + DDLogVerbose(@"freezeAllParseQueues done (inside barrier)"); + }); DDLogInfo(@"All parse queues frozen now"); }