From f40584616ecc9364fba8d3c2b9696e197340d97c Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Thu, 15 Mar 2018 16:01:50 -0400 Subject: [PATCH] (fix) avoid potential cache update when breaking sync queries (fixes #4422) --- ActiveSync/SOGoActiveSyncDispatcher+Sync.m | 42 ++++++++++++++-------- NEWS | 2 ++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m index 2a875e0ab..e15cb53b5 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m +++ b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m @@ -2602,9 +2602,36 @@ FIXME // We enter our loop detection change for (i = 0; i < (heartbeatInterval/internalInterval); i++) { + // Terminate the process if we need to if ([self easShouldTerminate]) break; + // We first check of any of the collections we want to sync are already + // in an other sync process. If that's the case, we do not do anything + // and we return immediately. So we'll let the other sync process terminate + for (j = 0; j < [allCollections count]; j++) + { + aCollection = [allCollections objectAtIndex: j]; + globalMetadata = [self globalMetadataForDevice]; + + key = [NSString stringWithFormat: @"SyncRequest+%@", [[[(id)[aCollection getElementsByTagName: @"CollectionId"] lastObject] textValue] stringByUnescapingURL]]; + + if (!([[globalMetadata objectForKey: key] isEqual: processIdentifier])) + { + if (debugOn) + [self logWithFormat: @"EAS - Discard response %@", [self globalMetadataForDevice]]; + + [output appendString: @"13"]; + [output appendString: @""]; + d = [[output dataUsingEncoding: NSUTF8StringEncoding] xml2wbxml]; + [theResponse setContent: d]; + RELEASE(output); + return; + } + + } + + // We're good to go to sync the collections s = [NSMutableString string]; for (j = 0; j < [allCollections count]; j++) @@ -2616,21 +2643,6 @@ FIXME changeDetected: &changeDetected maxSyncResponseSize: maxSyncResponseSize]; - // Don't return a response if another Sync is waiting. - globalMetadata = [self globalMetadataForDevice]; - key = [NSString stringWithFormat: @"SyncRequest+%@", [[[(id)[aCollection getElementsByTagName: @"CollectionId"] lastObject] textValue] stringByUnescapingURL]]; - - if (!([[globalMetadata objectForKey: key] isEqual: processIdentifier])) - { - if (debugOn) - [self logWithFormat: @"EAS - Discard response %@", [self globalMetadataForDevice]]; - - [theResponse setStatus: 503]; - - RELEASE(output); - return; - } - if ((maxSyncResponseSize > 0 && [s length] >= maxSyncResponseSize)) break; } diff --git a/NEWS b/NEWS index 7a2e33b26..4f7672317 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ Bug fixes - [web] prevent deletion of special folders using del key - [eas] improved alarms syncing with EAS devices (#4351) + - [eas] avoid potential cache update when breaking sync queries (#4422) + New features - [core] full S/MIME support - [core] can now invite attendees to exceptions only (#2561)