Skip to content

Commit 6f12f38

Browse files
authored
Make snapshots in sync listener registration removal idempotent (#5945)
1 parent eb6d343 commit 6f12f38

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,15 @@ - (void)testSnapshotsInSyncListenerFiresAfterListenersInSync {
568568
[self writeDocumentRef:ref data:@{@"foo" : @3}];
569569
}
570570

571+
- (void)testSnapshotsInSyncRemoveIsIdempotent {
572+
// This test merely verifies that calling remove multiple times doesn't
573+
// explode.
574+
auto listener = [self.db addSnapshotsInSyncListener:^(){
575+
}];
576+
[listener remove];
577+
[listener remove];
578+
}
579+
571580
- (void)testListenCanBeCalledMultipleTimes {
572581
FIRCollectionReference *coll = [self.db collectionWithPath:@"collection"];
573582
FIRDocumentReference *doc = [coll documentWithAutoID];

Firestore/core/src/api/snapshots_in_sync_listener_registration.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ void SnapshotsInSyncListenerRegistration::Remove() {
3636
if (async_listener) {
3737
async_listener->Mute();
3838
async_listener_.reset();
39-
}
4039

41-
client_->RemoveSnapshotsInSyncListener(async_listener);
42-
client_.reset();
40+
if (client_) {
41+
client_->RemoveSnapshotsInSyncListener(async_listener);
42+
client_.reset();
43+
}
44+
}
4345
}
4446

4547
} // namespace api

0 commit comments

Comments
 (0)