Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1391 from facebook/ImageNodeDeadlock
Browse files Browse the repository at this point in the history
[ASImageNode] -setDefaultImage: should release lock before calling -setImage:
  • Loading branch information
appleguy committed Mar 17, 2016
2 parents 5788e40 + a966b7b commit 37a0ba2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions AsyncDisplayKit/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,22 @@ - (NSURL *)URL

- (void)setDefaultImage:(UIImage *)defaultImage
{
ASDN::MutexLocker l(_lock);
_lock.lock();

if (ASObjectIsEqual(defaultImage, _defaultImage)) {
_lock.unlock();
return;
}
_defaultImage = defaultImage;

if (!_imageLoaded) {
self.image = _defaultImage;
_lock.unlock();
// Locking: it is important to release _lock before entering setImage:, as it needs to release the lock before -invalidateCalculatedLayout.
// If we continue to hold the lock here, it will still be locked until the next unlock() call, causing a possible deadlock with
// -[ASNetworkImageNode displayWillStart] (which is called on a different thread / main, at an unpredictable time due to ASMainRunloopQueue).
self.image = defaultImage;
} else {
_lock.unlock();
}
}

Expand Down

0 comments on commit 37a0ba2

Please sign in to comment.