Skip to content

Commit

Permalink
6.4.7-rc1 (#1303)
Browse files Browse the repository at this point in the history
- Fix some rare crashes
  • Loading branch information
tmolitor-stud-tu authored Nov 21, 2024
2 parents b31093f + 513cdec commit 8294833
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 42 deletions.
10 changes: 6 additions & 4 deletions Monal/Classes/DataLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,14 @@ -(void) persistState:(NSDictionary*) state forAccount:(NSNumber*) accountNo

-(BOOL) addSelfChatForAccount:(NSNumber*) accountNo
{
BOOL encrypt = NO;
return [self.db boolWriteTransaction:^{
BOOL encrypt = NO;
#ifndef DISABLE_OMEMO
encrypt = [[HelperTools defaultsDB] boolForKey:@"OMEMODefaultOn"];
encrypt = [[HelperTools defaultsDB] boolForKey:@"OMEMODefaultOn"];
#endif// DISABLE_OMEMO
NSDictionary* accountDetails = [self detailsForAccount:accountNo];
return [self.db executeNonQuery:@"INSERT INTO buddylist ('account_id', 'buddy_name', 'full_name', 'nick_name', 'muc', 'muc_nick', 'encrypt') VALUES(?, ?, ?, ?, ?, ?, ?) ON CONFLICT(account_id, buddy_name) DO UPDATE SET subscription='both';" andArguments:@[accountNo, [NSString stringWithFormat:@"%@@%@", accountDetails[kUsername], accountDetails[kDomain]], @"", @"", @0, @"", @(encrypt)]];
NSDictionary* accountDetails = [self detailsForAccount:accountNo];
return [self.db executeNonQuery:@"INSERT INTO buddylist ('account_id', 'buddy_name', 'full_name', 'nick_name', 'muc', 'muc_nick', 'encrypt') VALUES(?, ?, ?, ?, ?, ?, ?) ON CONFLICT(account_id, buddy_name) DO UPDATE SET subscription='both';" andArguments:@[accountNo, [NSString stringWithFormat:@"%@@%@", accountDetails[kUsername], accountDetails[kDomain]], @"", @"", @0, @"", @(encrypt)]];
}];
}

-(BOOL) addContact:(NSString*) contact forAccount:(NSNumber*) accountNo nickname:(NSString*) nickName
Expand Down
2 changes: 2 additions & 0 deletions Monal/Classes/HelperTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ void swizzle(Class c, SEL orig, SEL new);
+(void) installExceptionHandler;
+(int) pendingCrashreportCount;
+(void) flushLogsWithTimeout:(double) timeout;
+(void) signalSuspension;
+(void) signalResumption;
+(void) __attribute__((noreturn)) MLAssertWithText:(NSString*) text andUserData:(id _Nullable) additionalData andFile:(const char* const) file andLine:(int) line andFunc:(const char* const) func;
+(void) __attribute__((noreturn)) handleRustPanicWithText:(NSString*) text andBacktrace:(NSString*) backtrace;
+(void) __attribute__((noreturn)) throwExceptionWithName:(NSString*) name reason:(NSString*) reason userInfo:(NSDictionary* _Nullable) userInfo;
Expand Down
28 changes: 28 additions & 0 deletions Monal/Classes/HelperTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ -(void) invalidate;
static char _origLogfilePath[1024] = "";
static char _logfilePath[1024] = "";
static NSObject* _isAppExtensionLock = nil;
static NSObject* _suspensionHandlingLock = nil;
static BOOL _suspensionHandlingIsSuspended = NO;
static NSMutableDictionary* _versionInfoCache;
static MLStreamRedirect* _stdoutRedirector = nil;
static MLStreamRedirect* _stderrRedirector = nil;
Expand Down Expand Up @@ -295,6 +297,8 @@ @implementation HelperTools

+(void) initialize
{
_suspensionHandlingLock = [NSObject new];
_suspensionHandlingIsSuspended = NO;
_isAppExtensionLock = [NSObject new];
_versionInfoCache = [NSMutableDictionary new];

Expand Down Expand Up @@ -1874,6 +1878,30 @@ +(void) flushLogsWithTimeout:(double) timeout
[MLUDPLogger flushWithTimeout:timeout];
}

+(void) signalSuspension
{
DDLogVerbose(@"Suspending logger queue...");
[HelperTools flushLogsWithTimeout:0.100];
@synchronized(_suspensionHandlingLock) {
dispatch_suspend([DDLog loggingQueue]);
_suspensionHandlingIsSuspended = YES;
}
DDLogVerbose(@"Posting kMonalIsFreezed notification now...");
[[NSNotificationCenter defaultCenter] postNotificationName:kMonalIsFreezed object:nil];
}

+(void) signalResumption
{
@synchronized(_suspensionHandlingLock) {
if(_suspensionHandlingIsSuspended)
{
DDLogVerbose(@"Resuming logger queue...");
dispatch_resume([DDLog loggingQueue]);
_suspensionHandlingIsSuspended = NO;
}
}
}

+(void) configureXcodeLogging
{
//only start console logger
Expand Down
13 changes: 0 additions & 13 deletions Monal/Classes/MLMucProcessor.m
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,6 @@ -(void) configureMuc:(NSString*) roomJid withMandatoryOptions:(NSDictionary*) ma
$$

$$instance_handler(handleRoomConfigForm, account.mucProcessor, $$ID(xmpp*, account), $$ID(XMPPIQ*, iqNode), $$ID(NSString*, roomJid), $$ID(NSDictionary*, mandatoryOptions), $$ID(NSDictionary*, optionalOptions), $$BOOL(deleteOnError), $$BOOL(joinOnSuccess))
MLAssert([iqNode.fromUser isEqualToString:roomJid], @"Room config form response jid not matching query jid!", (@{
@"iqNode.fromUser": [NSString stringWithFormat:@"%@", iqNode.fromUser],
@"roomJid": [NSString stringWithFormat:@"%@", roomJid],
}));
if([iqNode check:@"/<type=error>"])
{
DDLogError(@"Failed to fetch room config form for '%@': %@", roomJid, [iqNode findFirst:@"error"]);
Expand Down Expand Up @@ -619,10 +615,6 @@ -(void) configureMuc:(NSString*) roomJid withMandatoryOptions:(NSDictionary*) ma
[self handleError:[NSString stringWithFormat:NSLocalizedString(@"Could not configure group '%@'", @""), roomJid] forMuc:roomJid withNode:iqNode andIsSevere:YES];
return;
}
MLAssert([iqNode.fromUser isEqualToString:roomJid], @"Room config form response jid not matching query jid!", (@{
@"iqNode.fromUser": [NSString stringWithFormat:@"%@", iqNode.fromUser],
@"roomJid": [NSString stringWithFormat:@"%@", roomJid],
}));

//don't call success handler if we are only "half-joined" (see comments below for what that means)
if(joinOnSuccess)
Expand Down Expand Up @@ -1327,11 +1319,6 @@ -(void) publishAvatar:(UIImage* _Nullable) image forMuc:(NSString*) room
$$

$$instance_handler(handleDiscoResponse, account.mucProcessor, $$ID(xmpp*, account), $$ID(XMPPIQ*, iqNode), $$ID(NSString*, roomJid), $$BOOL(join), $$BOOL(updateBookmarks))
MLAssert([iqNode.fromUser isEqualToString:roomJid], @"Disco response jid not matching query jid!", (@{
@"iqNode.fromUser": [NSString stringWithFormat:@"%@", iqNode.fromUser],
@"roomJid": [NSString stringWithFormat:@"%@", roomJid],
}));

//no matter what the disco response is: we are not creating this muc anymore
//either because we successfully created it and called join afterwards,
//or because the user tried to simultaneously create and join this muc (the join has precendence in this case)
Expand Down
49 changes: 24 additions & 25 deletions Monal/Classes/MonalAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ -(void) updateUnread

-(BOOL) application:(UIApplication*) application willFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
//resume logging and other core tasks
[HelperTools signalResumption];

DDLogInfo(@"App launching with options: %@", launchOptions);

//init IPC and ProcessLock
Expand Down Expand Up @@ -662,6 +665,9 @@ -(void) windowHandling:(NSNotification*) notification
}
else if([notification.name isEqualToString:@"NSWindowDidBecomeKeyNotification"])
{
//resume logging and other core tasks
[HelperTools signalResumption];

DDLogInfo(@"Window got focus (key window)...");
[MLProcessLock lock];
@synchronized(self) {
Expand Down Expand Up @@ -1151,6 +1157,9 @@ -(void) prepareForFreeze:(NSNotification*) notification

-(void) applicationWillEnterForeground:(UIApplication*) application
{
//resume logging and other core tasks
[HelperTools signalResumption];

DDLogInfo(@"Entering FG");
[MLProcessLock lock];

Expand Down Expand Up @@ -1256,6 +1265,7 @@ -(void) applicationWillTerminate:(UIApplication *)application
[[MLXMPPManager sharedInstance] disconnectAll];
DDLogInfo(@"|~~| T E R M I N A T E D |~~|");
[DDLog flushLog];
[HelperTools flushLogsWithTimeout:0.025];
}
}

Expand Down Expand Up @@ -1464,11 +1474,7 @@ -(void) checkIfBackgroundTaskIsStillNeeded
[DDLog flushLog];
}
else
{
DDLogVerbose(@"Posting kMonalIsFreezed notification now...");
[[NSNotificationCenter defaultCenter] postNotificationName:kMonalIsFreezed object:nil];
[HelperTools flushLogsWithTimeout:0.100];
}
[HelperTools signalSuspension];
}];
}
}
Expand Down Expand Up @@ -1525,11 +1531,7 @@ -(void) addBackgroundTask
[[UIApplication sharedApplication] endBackgroundTask:task];

if(stopped)
{
DDLogVerbose(@"Posting kMonalIsFreezed notification now...");
[[NSNotificationCenter defaultCenter] postNotificationName:kMonalIsFreezed object:nil];
[HelperTools flushLogsWithTimeout:0.100];
}
[HelperTools signalSuspension];
}
}];
}
Expand Down Expand Up @@ -1588,15 +1590,14 @@ -(void) handleBackgroundProcessingTask:(BGTask*) task
[task setTaskCompletedWithSuccess:!background];

if(stopped)
{
DDLogVerbose(@"Posting kMonalIsFreezed notification now...");
[[NSNotificationCenter defaultCenter] postNotificationName:kMonalIsFreezed object:nil];
[HelperTools flushLogsWithTimeout:0.100];
}
[HelperTools signalSuspension];
}
}];
};

//resume logging and other core tasks
[HelperTools signalResumption];

//only proceed with our BGTASK if the NotificationServiceExtension is not running
[MLProcessLock lock];
[[IPC sharedInstance] sendMessage:@"Monal.disconnectAll" withData:nil to:@"NotificationServiceExtension"];
Expand Down Expand Up @@ -1696,15 +1697,14 @@ -(void) handleBackgroundRefreshingTask:(BGTask*) task
[task setTaskCompletedWithSuccess:!background];

if(stopped)
{
DDLogVerbose(@"Posting kMonalIsFreezed notification now...");
[[NSNotificationCenter defaultCenter] postNotificationName:kMonalIsFreezed object:nil];
[HelperTools flushLogsWithTimeout:0.100];
}
[HelperTools signalSuspension];
}
}];
};

//resume logging and other core tasks
[HelperTools signalResumption];

//only proceed with our BGTASK if the NotificationServiceExtension is not running
[MLProcessLock lock];
[[IPC sharedInstance] sendMessage:@"Monal.disconnectAll" withData:nil to:@"NotificationServiceExtension"];
Expand Down Expand Up @@ -1845,6 +1845,9 @@ -(void) connectIfNecessaryWithOptions:(NSDictionary*) options

-(void) incomingWakeupWithCompletionHandler:(void (^)(UIBackgroundFetchResult result)) completionHandler
{
//resume logging and other core tasks
[HelperTools signalResumption];

if(![HelperTools isInBackground])
{
DDLogWarn(@"Ignoring incomingWakeupWithCompletionHandler: because app is in FG!");
Expand Down Expand Up @@ -1918,11 +1921,7 @@ -(void) incomingWakeupWithCompletionHandler:(void (^)(UIBackgroundFetchResult re
completionHandler(UIBackgroundFetchResultFailed);

if(stopped)
{
DDLogVerbose(@"Posting kMonalIsFreezed notification now...");
[[NSNotificationCenter defaultCenter] postNotificationName:kMonalIsFreezed object:nil];
[HelperTools flushLogsWithTimeout:0.100];
}
[HelperTools signalSuspension];

//trigger disconnect if we are idle and no timer is blocking us now
if(self->_bgTask != UIBackgroundTaskInvalid || self->_bgProcessing != nil || self->_bgRefreshing != nil)
Expand Down

0 comments on commit 8294833

Please sign in to comment.