From 48acb8e4233f92bc4db07fc70815b09f0f917515 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 4 Jun 2018 20:16:27 +0800 Subject: [PATCH] Fix that the downloader operation may not call the completion block in race condition, which the operation we get is finished but not been removed from the operation array. --- SDWebImage/SDWebImageDownloader.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index f775a249..76291a17 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -275,7 +275,8 @@ LOCK(self.operationsLock); 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(); __weak typeof(self) wself = self; operation.completionBlock = ^{