Skip to content

Commit

Permalink
Request background task before disconnecting
Browse files Browse the repository at this point in the history
This makes sure we get it even when killed by some watchdog while
disconnecting/shutting down
  • Loading branch information
tmolitor-stud-tu committed Dec 29, 2024
1 parent c170658 commit 7b95939
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions Monal/Classes/MonalAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -1412,8 +1412,8 @@ -(void) checkIfBackgroundTaskIsStillNeeded
[DDLog flushLog];
DDLogVerbose(@"Setting _shutdownPending to YES...");
_shutdownPending = YES;
[[MLXMPPManager sharedInstance] disconnectAll]; //disconnect all accounts to prevent TCP buffer leaking
[HelperTools scheduleBackgroundTask:NO]; //request bg fetch execution in BGFETCH_DEFAULT_INTERVAL seconds
[[MLXMPPManager sharedInstance] disconnectAll]; //disconnect all accounts to prevent TCP buffer leaking
[HelperTools dispatchAsync:NO reentrantOnQueue:dispatch_get_main_queue() withBlock:^{
BOOL stopped = NO;
//make sure this will be done only once, even if we have an uikit bgtask and a bg fetch running simultaneously
Expand Down Expand Up @@ -1490,13 +1490,13 @@ -(void) addBackgroundTask
//this has to be before account disconnects, to detect which accounts are not idle (e.g. have a sync error)
[HelperTools updateSyncErrorsWithDeleteOnly:NO andWaitForCompletion:YES];

//disconnect all accounts to prevent TCP buffer leaking
[[MLXMPPManager sharedInstance] disconnectAll];

//schedule a BGProcessingTaskRequest to process this further as soon as possible
//(if we end up here, the graceful shuttdown did not work out because we are not idle --> we need more cpu time)
[HelperTools scheduleBackgroundTask:YES]; //force as soon as possible

//disconnect all accounts to prevent TCP buffer leaking
[[MLXMPPManager sharedInstance] disconnectAll];

//notify about pending app freeze (don't queue this notification because it should be handled IMMEDIATELY and INLINE)
DDLogVerbose(@"Posting kMonalWillBeFreezed notification now...");
[[NSNotificationCenter defaultCenter] postNotificationName:kMonalWillBeFreezed object:nil];
Expand Down Expand Up @@ -1549,13 +1549,13 @@ -(void) handleBackgroundProcessingTask:(BGTask*) task
//this has to be before account disconnects, to detect which accounts are not idle (e.g. have a sync error)
[HelperTools updateSyncErrorsWithDeleteOnly:YES andWaitForCompletion:YES];

//disconnect all accounts to prevent TCP buffer leaking
[[MLXMPPManager sharedInstance] disconnectAll];

//schedule a new BGProcessingTaskRequest to process this further as soon as possible
//(if we end up here, the graceful shuttdown did not work out because we are not idle --> we need more cpu time)
[HelperTools scheduleBackgroundTask:YES]; //force as soon as possible

//disconnect all accounts to prevent TCP buffer leaking
[[MLXMPPManager sharedInstance] disconnectAll];

//notify about pending app freeze (don't queue this notification because it should be handled IMMEDIATELY and INLINE)
DDLogVerbose(@"Posting kMonalWillBeFreezed notification now...");
[[NSNotificationCenter defaultCenter] postNotificationName:kMonalWillBeFreezed object:nil];
Expand Down Expand Up @@ -1653,13 +1653,13 @@ -(void) handleBackgroundRefreshingTask:(BGTask*) task
//this has to be before account disconnects, to detect which accounts are not idle (e.g. have a sync error)
[HelperTools updateSyncErrorsWithDeleteOnly:YES andWaitForCompletion:YES];

//disconnect all accounts to prevent TCP buffer leaking
[[MLXMPPManager sharedInstance] disconnectAll];

//schedule a new BGProcessingTaskRequest to process this further as soon as possible
//(if we end up here, the graceful shuttdown did not work out because we are not idle --> we need more cpu time)
[HelperTools scheduleBackgroundTask:YES]; //force as soon as possible

//disconnect all accounts to prevent TCP buffer leaking
[[MLXMPPManager sharedInstance] disconnectAll];

//notify about pending app freeze (don't queue this notification because it should be handled IMMEDIATELY and INLINE)
DDLogVerbose(@"Posting kMonalWillBeFreezed notification now...");
[[NSNotificationCenter defaultCenter] postNotificationName:kMonalWillBeFreezed object:nil];
Expand Down Expand Up @@ -1880,13 +1880,13 @@ -(void) incomingWakeupWithCompletionHandler:(void (^)(UIBackgroundFetchResult re
BOOL wasIdle = [[MLXMPPManager sharedInstance] allAccountsIdle] && [MLFiletransfer isIdle];
[HelperTools updateSyncErrorsWithDeleteOnly:NO andWaitForCompletion:YES];

//disconnect all accounts to prevent TCP buffer leaking
[[MLXMPPManager sharedInstance] disconnectAll];

//schedule a new BGProcessingTaskRequest to process this further as soon as possible, if we are not idle
//(if we end up here, the graceful shuttdown did not work out because we are not idle --> we need more cpu time)
[HelperTools scheduleBackgroundTask:!wasIdle];

//disconnect all accounts to prevent TCP buffer leaking
[[MLXMPPManager sharedInstance] disconnectAll];

//notify about pending app freeze (don't queue this notification because it should be handled IMMEDIATELY and INLINE)
DDLogVerbose(@"Posting kMonalWillBeFreezed notification now...");
[[NSNotificationCenter defaultCenter] postNotificationName:kMonalWillBeFreezed object:nil];
Expand Down

0 comments on commit 7b95939

Please sign in to comment.