Skip to content

Commit

Permalink
CBL-5077 : Fix close database could hang waiting for active component…
Browse files Browse the repository at this point in the history
…s to close (#3227)

* Cherry-Pick the fix (7daff8e) from lithum branch.

* When signal the database thread to wake up and check for the close, the close condition needs to be locked first to avoid race condition.
  • Loading branch information
pasin authored Feb 14, 2024
1 parent 0686541 commit 3c30fa8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Objective-C/CBLDatabase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1124,9 +1124,11 @@ - (void) addActiveStoppable: (id<CBLStoppable>)stoppable {
- (void) removeActiveStoppable: (id<CBLStoppable>)stoppable {
CBL_LOCK(_mutex) {
[_activeStoppables removeObject: stoppable];

if (_activeStoppables.count == 0)
if (_activeStoppables.count == 0) {
[_closeCondition lock];
[_closeCondition broadcast];
[_closeCondition unlock];
}
}
}

Expand Down

0 comments on commit 3c30fa8

Please sign in to comment.