Authored by DreamPiggy
Committed by GitHub

Merge pull request #2346 from dreampiggy/fix_operation_race_condition

Fix that the downloader operation may not call the completion block in race condition
@@ -275,7 +275,8 @@ @@ -275,7 +275,8 @@
275 275
276 LOCK(self.operationsLock); 276 LOCK(self.operationsLock);
277 SDWebImageDownloaderOperation *operation = [self.URLOperations objectForKey:url]; 277 SDWebImageDownloaderOperation *operation = [self.URLOperations objectForKey:url];
278 - if (!operation) { 278 + // There is a case that the operation may be marked as finished, but not been removed from `self.URLOperations`.
  279 + if (!operation || operation.isFinished) {
279 operation = createCallback(); 280 operation = createCallback();
280 __weak typeof(self) wself = self; 281 __weak typeof(self) wself = self;
281 operation.completionBlock = ^{ 282 operation.completionBlock = ^{