Skip to content

Commit

Permalink
(fix) prevent double Sync ops from same device (fixes #3603)
Browse files Browse the repository at this point in the history
  • Loading branch information
extrafu committed Mar 28, 2016
1 parent f3a8c30 commit 5a342f2
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions ActiveSync/SOGoActiveSyncDispatcher.m
Expand Up @@ -2016,11 +2016,12 @@ - (void) processMoveItems: (id <DOMElement>) theDocumentElement
- (void) processPing: (id <DOMElement>) theDocumentElement
inResponse: (WOResponse *) theResponse
{
NSString *collectionId, *realCollectionId, *syncKey;
NSString *collectionId, *realCollectionId, *syncKey, *processIdentifier, *pingRequestInCache;
NSMutableArray *foldersWithChanges, *allFoldersID;
SOGoMicrosoftActiveSyncFolderType folderType;
NSMutableDictionary *folderMetadata;
SOGoSystemDefaults *defaults;
SOGoCacheGCSObject *o;
id <DOMElement> aCollection;
NSArray *allCollections;

Expand All @@ -2029,8 +2030,17 @@ - (void) processPing: (id <DOMElement>) theDocumentElement
NSData *d;
NSAutoreleasePool *pool;

int i, j, heartbeatInterval, defaultInterval, internalInterval, status;
int i, j, heartbeatInterval, defaultInterval, internalInterval, status, total_sleep;

// Let other ping requests know that a new request has arrived.
processIdentifier = [NSString stringWithFormat: @"%d", [[NSProcessInfo processInfo] processIdentifier]];
o = [SOGoCacheGCSObject objectWithName: [context objectForKey: @"DeviceId"] inContainer: nil useCache: NO];
[o setObjectType: ActiveSyncGlobalCacheObject];
[o setTableUrl: [self folderTableURL]];
[o reloadIfNeeded];
[[o properties] setObject: processIdentifier forKey: @"PingRequest"];
[o save];

defaults = [SOGoSystemDefaults sharedSystemDefaults];
defaultInterval = [defaults maximumPingInterval];
internalInterval = [defaults internalSyncInterval];
Expand Down Expand Up @@ -2124,8 +2134,30 @@ - (void) processPing: (id <DOMElement>) theDocumentElement
}
else
{
[self logWithFormat: @"Sleeping %d seconds while detecting changes in Ping...", internalInterval];
sleep(internalInterval);
total_sleep = 0;

while (total_sleep < internalInterval)
{
// We check if we must break the current ping request since an other ping request
// has just arrived.
pingRequestInCache = [[self globalMetadataForDevice] objectForKey: @"PingRequest"];
if (pingRequestInCache && ![pingRequestInCache isEqualToString: processIdentifier])
{
if (debugOn)
[self logWithFormat: @"EAS - Ping request canceled (%@)", pingRequestInCache];

// Make sure we end the heardbeat-loop.
internalInterval = heartbeatInterval;

break;
}
else
{
[self logWithFormat: @"Sleeping %d seconds while detecting changes in Ping...", internalInterval-total_sleep];
sleep(5);
total_sleep += 5;
}
}
}
}

Expand Down

0 comments on commit 5a342f2

Please sign in to comment.