DropboxSync icon indicating copy to clipboard operation
DropboxSync copied to clipboard

Can't Cancel Sync in Progress if Dropbox Unreachable

Open steveshepard opened this issue 13 years ago • 0 comments

Hi Jesse,

Found this one in the course of "pull the cable" testing.

If Dropbox is unreachable when you start a sync, FolderSyncPathOperation can't load metadata. The db client will eventually time out (~ 2 minutes, I think), but you can't cancel the sync before that time with cancelSyncInProgress because:

  • cancelSyncInProgress calls [folderSyncPathOperationOperationQueue cancelAllOperations]
  • -[FolderSyncPathOperation cancel] calls -[PathOperation cancel]
  • -[PathOperation cancel] simply returns without canceling if self.isExecuting is YES.
  • The only way self.isExecuting is NO is if a path operation calls finish:
  • Since the metadata isn't loaded yet, there are no path operations (except for the FolderSyncOperation) to call finish: so the cancel never completes.

I'm not sure why self.isExecuting is blocking the cancel (I suspect there are some path operations that need to complete), so I've worked around this specific case by setting isExecuting to NO in -[FolderSyncPathOperation cancel] as follows:

- (void)cancel {
    if (![NSThread isMainThread]) {
        [self performSelectorOnMainThread:@selector(cancel) withObject:nil waitUntilDone:NO];
        return;
    }

    [[[pathOperations copy] autorelease] makeObjectsPerformSelector:@selector(cancel)];
    needsCleanupSync = NO;
    updatedLastSyncHashOnFinish = NO;

    if (!loadedMetadata) {
        if (pathOperations.count == 0) {
            [self willChangeValueForKey:@"isExecuting"];
            isExecuting = NO;
            [self didChangeValueForKey:@"isExecuting"];
        }
        [super cancel];
    }
}

Since there are no path operations, the only thing to cancel is the metadata request, which will now be cancelled in [super cancel].

I reproduce this by disconnecting my wireless router from the cable modem.

-Steve

steveshepard avatar Jul 25 '11 18:07 steveshepard