Skip to content

Commit

Permalink
Dispatch delegate messages in a safer manner
Browse files Browse the repository at this point in the history
Should address issues like
https://rink.hockeyapp.net/manage/apps/101581/app_versions/18/crash_reas
ons/20702812?order=asc&sort_by=date&type=crashes#crash_data
  • Loading branch information
mikeabdullah committed Oct 18, 2014
1 parent ea70424 commit 3feea52
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ConnectionKit/CK2FileOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,18 @@ - (void)tryToMessageDelegateSelector:(SEL)selector usingBlock:(void (^)(id <CK2F
{
CK2FileManager *manager = self.fileManager;
NSAssert(manager, @"%@ disconnected from its manager too early", self.class);
id <CK2FileManagerDelegate> delegate = manager.delegate;

if (!selector || [delegate respondsToSelector:selector]) // will crash if delegate is a zombie, as in https://rink.hockeyapp.net/manage/apps/101581/crash_reasons/21102964/multiple
{
[manager.delegateQueue addOperationWithBlock:^{
block(manager.delegate); // I have a suspicion delegate is occasionally a zombie otherwise https://karelia.fogbugz.com/f/cases/236528
}];
}
// Clients could change the delegate at any time. If we trust them to do so in concert with the
// delegate queue, then that can be made reasonably safe by only accessing the delegate from
// within the queue.
// It's still inherently a bit dangerous though, as the client could change it on a different
// queue, or could have specified a non-serial delegate queue.
[manager.delegateQueue addOperationWithBlock:^{
id <CK2FileManagerDelegate> delegate = manager.delegate;
if (!selector || [delegate respondsToSelector:selector]) {
block(delegate);
}
}];
}

#pragma mark URL & Requests
Expand Down

0 comments on commit 3feea52

Please sign in to comment.