Skip to content

Commit e535f70

Browse files
Fix endless loop adding and removing omemo devices
When removing an old omemo device not seen for longer than 90 days, that device might still be active (just not sending messages) and immediately add itself back into the devicelist. This will cause a bundle fetch. We don't want to delete the device again for not being known if the bundle fetch is still pending. Similarly for session repairs and queued key transport messages.
1 parent ab3feb5 commit e535f70

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

Monal/Classes/MLOMEMO.m

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ -(void) repairQueuedSessions
286286
[self checkBundleFetchCount];
287287

288288
DDLogVerbose(@"New state: %@", self.state);
289+
290+
[self cleanupOwnOldDevices];
289291
}
290292

291293
-(void) retriggerKeyTransportElementsForJid:(NSString*) jid
@@ -308,6 +310,8 @@ -(void) retriggerKeyTransportElementsForJid:(NSString*) jid
308310
[self.state.queuedKeyTransportElements removeObjectForKey:jid];
309311
[self sendKeyTransportElement:jid forRids:rids];
310312
}
313+
314+
[self cleanupOwnOldDevices];
311315
}
312316

313317
$$instance_handler(devicelistHandler, account.omemo, $$ID(xmpp*, account), $$ID(NSString*, node), $$ID(NSString*, jid), $$ID(NSString*, type), $_ID((NSDictionary<NSString*, MLXMLNode*>*), data))
@@ -562,8 +566,30 @@ -(void) handleOwnDevicelistUpdate:(NSSet<NSNumber*>*) receivedDevices
562566

563567
-(void) cleanupOwnOldDevices
564568
{
565-
NSMutableArray* deletedDevices = [NSMutableArray new];
566569
NSString* jid = self.account.connectionProperties.identity.jid;
570+
571+
//don't try to clean up in all these cases
572+
@synchronized(self.state.queuedKeyTransportElements) {
573+
if(self.state.queuedKeyTransportElements[jid] != nil && [self.state.queuedKeyTransportElements[jid] count] > 0)
574+
{
575+
DDLogWarn(@"Not cleaning up own old devices: key transport elements still queued!");
576+
return
577+
}
578+
}
579+
@synchronized(self.state.queuedSessionRepairs) {
580+
if(self.state.queuedSessionRepairs[jid] != nil && [self.state.queuedSessionRepairs[jid] count] > 0)
581+
{
582+
DDLogWarn(@"Not cleaning up own old devices: session repairs still queued!");
583+
return
584+
}
585+
}
586+
if(self.state.openBundleFetches[jid] != nil && self.state.openBundleFetches[jid].count > 0)
587+
{
588+
DDLogWarn(@"Not cleaning up own old devices: bundle fetches still pending!");
589+
return
590+
}
591+
592+
NSMutableArray* deletedDevices = [NSMutableArray new];
567593
for(NSNumber* device in [self.ownDeviceList copy])
568594
{
569595
SignalAddress* address = [[SignalAddress alloc] initWithName:jid deviceId:(uint32_t)device.unsignedIntValue];

0 commit comments

Comments
 (0)