Merge pull request #2346 from dreampiggy/fix_operation_race_condition

Fix that the downloader operation may not call the completion block in race condition
This commit is contained in:
DreamPiggy 2018-06-06 14:25:59 +08:00 committed by GitHub
commit e13f503125
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -275,7 +275,8 @@
LOCK(self.operationsLock); LOCK(self.operationsLock);
SDWebImageDownloaderOperation *operation = [self.URLOperations objectForKey:url]; SDWebImageDownloaderOperation *operation = [self.URLOperations objectForKey:url];
if (!operation) { // There is a case that the operation may be marked as finished, but not been removed from `self.URLOperations`.
if (!operation || operation.isFinished) {
operation = createCallback(); operation = createCallback();
__weak typeof(self) wself = self; __weak typeof(self) wself = self;
operation.completionBlock = ^{ operation.completionBlock = ^{