aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Database
diff options
context:
space:
mode:
authorGravatar Sebastian Schmidt <mrschmidt@google.com>2018-04-09 16:32:38 -0700
committerGravatar Sebastian Schmidt <mrschmidt@google.com>2018-04-09 16:32:38 -0700
commit22334407d3551e4a1d9426a77c410adb65a73848 (patch)
treee1e6383548152f2830f96154561ff15208dd29ea /Firebase/Database
parent0a6618705389543191a8c44278d4c6791c84602a (diff)
Fixing concurrent modification when we cancel transaction
Diffstat (limited to 'Firebase/Database')
-rw-r--r--Firebase/Database/Core/FPersistentConnection.m16
1 files changed, 10 insertions, 6 deletions
diff --git a/Firebase/Database/Core/FPersistentConnection.m b/Firebase/Database/Core/FPersistentConnection.m
index 870727c..c32d18c 100644
--- a/Firebase/Database/Core/FPersistentConnection.m
+++ b/Firebase/Database/Core/FPersistentConnection.m
@@ -735,18 +735,22 @@ static void reachabilityCallback(SCNetworkReachabilityRef ref, SCNetworkReachabi
}
- (void) cancelSentTransactions {
- NSMutableArray* toPrune = [[NSMutableArray alloc] init];
+ NSMutableDictionary<NSNumber*, FOutstandingPut*>* cancelledOutstandingPuts = [[NSMutableDictionary alloc] init];
+
for (NSNumber* index in self.outstandingPuts) {
FOutstandingPut* put = self.outstandingPuts[index];
if (put.request[kFWPRequestHash] && put.sent) {
- // This is a sent transaction put
- put.onCompleteBlock(kFTransactionDisconnect, @"Client was disconnected while running a transaction");
- [toPrune addObject:index];
+ // This is a sent transaction put.
+ cancelledOutstandingPuts[index] = put;
}
}
- for (NSNumber* index in toPrune) {
+
+ [cancelledOutstandingPuts enumerateKeysAndObjectsUsingBlock:^(NSNumber *index, FOutstandingPut *outstandingPut, BOOL *stop) {
+ // `onCompleteBlock:` may invoke `rerunTransactionsForPath:` and enqueue new writes. We defer calling
+ // it until we have finished enumerating all existing writes.
+ outstandingPut.onCompleteBlock(kFTransactionDisconnect, @"Client was disconnected while running a transaction");
[self.outstandingPuts removeObjectForKey:index];
- }
+ }];
}
- (void) onDataPushWithAction:(NSString *)action andBody:(NSDictionary *)body {