Skip to content

Commit

Permalink
Fix crash in CBLRemoteSession when
Browse files Browse the repository at this point in the history
* The issue hapens due to the race between setting the _session to nil in the -URLSession:didBecomeInvalidWithError: delegate method and calling NSURLSession’s finishTasksAndInvalidate when closing the CBLRemoteSession. The issue is a regression of fixing #1429 (race of resetting _allRequests).

* Solution: created a strong session that will exists through the block execution.

* Note: Calling NSURLSessions’s -finishTasksAndInvalidate after the sesion is invalidated is no-ops operation (from manual testing).

#1923
  • Loading branch information
pasin committed Oct 12, 2017
1 parent 099e588 commit 0b51fbb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Source/CBLRemoteSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@ - (void)dealloc {


- (void) close {
[_session.delegateQueue addOperationWithBlock:^{
// Create a strong session in block to prevent race when _session
// is set to nil in the -URLSession:didBecomeInvalidWithError: method.
NSURLSession* session = _session;
[_session.delegateQueue addOperationWithBlock: ^{
// Do this on the queue so that it's properly ordered with the tasks being started in
// the -startRequest method.
LogTo(RemoteRequest, @"CBLRemoteSession closing");
[_session finishTasksAndInvalidate];
[session finishTasksAndInvalidate];
_requestDelegate = nil;
}];
}
Expand Down

0 comments on commit 0b51fbb

Please sign in to comment.