Skip to content

Commit 881f605

Browse files
authored
Merge branch 'main' into pb-rtdb-file-protection
2 parents c2413f2 + 3c30cd9 commit 881f605

File tree

5 files changed

+48
-37
lines changed

5 files changed

+48
-37
lines changed

FirebaseAuth/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22
- [fixed] Add a mechanism to prevent concurrent token refreshes. (#15474)
3+
- [fixed] Fix "weak never mutated" build warning introduced in Xcode 26.2.
34

45
# 12.2.0
56
- [added] Added TOTP support for macOS.

FirebaseAuth/Sources/Swift/Auth/Auth.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,30 +1938,30 @@ extension Auth: AuthInterop {
19381938
"for the new token.")
19391939
}
19401940
autoRefreshScheduled = true
1941-
weak var weakSelf = self
1942-
authDispatcher.dispatch(afterDelay: delay, queue: kAuthGlobalWorkQueue) {
1943-
guard let strongSelf = weakSelf else {
1941+
authDispatcher.dispatch(afterDelay: delay, queue: kAuthGlobalWorkQueue) { [weak self] in
1942+
guard let self else {
19441943
return
19451944
}
1946-
guard strongSelf._currentUser?.rawAccessToken() == accessToken else {
1945+
guard self._currentUser?.rawAccessToken() == accessToken else {
19471946
// Another auto refresh must have been scheduled, so keep _autoRefreshScheduled unchanged.
19481947
return
19491948
}
1950-
strongSelf.autoRefreshScheduled = false
1951-
if strongSelf.isAppInBackground {
1949+
self.autoRefreshScheduled = false
1950+
if self.isAppInBackground {
19521951
return
19531952
}
1954-
let uid = strongSelf._currentUser?.uid
1955-
strongSelf._currentUser?
1956-
.internalGetToken(forceRefresh: true, backend: strongSelf.backend) { token, error in
1957-
if strongSelf._currentUser?.uid != uid {
1953+
let uid = self._currentUser?.uid
1954+
self._currentUser?
1955+
.internalGetToken(forceRefresh: true, backend: self.backend) { [weak self] token, error in
1956+
guard let self else { return }
1957+
if self._currentUser?.uid != uid {
19581958
return
19591959
}
19601960
if error != nil {
19611961
// Kicks off exponential back off logic to retry failed attempt. Starts with one minute
19621962
// delay (60 seconds) if this is the first failed attempt.
19631963
let rescheduleDelay = retry ? min(delay * 2, 16 * 60) : 60
1964-
strongSelf.scheduleAutoTokenRefresh(withDelay: rescheduleDelay, retry: true)
1964+
self.scheduleAutoTokenRefresh(withDelay: rescheduleDelay, retry: true)
19651965
}
19661966
}
19671967
}

FirebaseDatabase/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22
- [fixed] Fix `Fatal Exception: FirebaseDatabasePersistenceFailure`. (#4493)
3+
- [fixed] Concurrency crash in FView. (#15514)
34

45
# 11.9.0
56
- [fixed] Fix connection failure issue introduced in 10.27.0 by restoring the

FirebaseDatabase/Sources/Core/View/FView.m

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ @interface FView ()
7070
@property(nonatomic, strong, readwrite) FQuerySpec *query;
7171
@property(nonatomic, strong) FViewProcessor *processor;
7272
@property(nonatomic, strong) FViewCache *viewCache;
73+
74+
// All accesses must be guarded by @synchronized(self.eventRegistrations)
7375
@property(nonatomic, strong) NSMutableArray *eventRegistrations;
7476
@property(nonatomic, strong) FEventGenerator *eventGenerator;
7577

@@ -165,11 +167,15 @@ - (id)initWithQuery:(FQuerySpec *)query
165167
}
166168

167169
- (BOOL)isEmpty {
168-
return self.eventRegistrations.count == 0;
170+
@synchronized(self.eventRegistrations) {
171+
return self.eventRegistrations.count == 0;
172+
}
169173
}
170174

171175
- (void)addEventRegistration:(id<FEventRegistration>)eventRegistration {
172-
[self.eventRegistrations addObject:eventRegistration];
176+
@synchronized(self.eventRegistrations) {
177+
[self.eventRegistrations addObject:eventRegistration];
178+
}
173179
}
174180

175181
/**
@@ -181,31 +187,33 @@ - (void)addEventRegistration:(id<FEventRegistration>)eventRegistration {
181187
- (NSArray *)removeEventRegistration:(id<FEventRegistration>)eventRegistration
182188
cancelError:(NSError *)cancelError {
183189
NSMutableArray *cancelEvents = [[NSMutableArray alloc] init];
184-
if (cancelError != nil) {
185-
NSAssert(eventRegistration == nil,
186-
@"A cancel should cancel all event registrations.");
187-
FPath *path = self.query.path;
188-
for (id<FEventRegistration> registration in self.eventRegistrations) {
189-
FCancelEvent *maybeEvent =
190-
[registration createCancelEventFromError:cancelError path:path];
191-
if (maybeEvent) {
192-
[cancelEvents addObject:maybeEvent];
190+
@synchronized(self.eventRegistrations) {
191+
if (cancelError != nil) {
192+
NSAssert(eventRegistration == nil,
193+
@"A cancel should cancel all event registrations.");
194+
FPath *path = self.query.path;
195+
for (id<FEventRegistration> registration in self
196+
.eventRegistrations) {
197+
FCancelEvent *maybeEvent =
198+
[registration createCancelEventFromError:cancelError
199+
path:path];
200+
if (maybeEvent) {
201+
[cancelEvents addObject:maybeEvent];
202+
}
193203
}
194204
}
195-
}
196205

197-
if (eventRegistration) {
198-
NSUInteger i = 0;
199-
while (i < self.eventRegistrations.count) {
200-
id<FEventRegistration> existing = self.eventRegistrations[i];
201-
if ([existing matches:eventRegistration]) {
202-
[self.eventRegistrations removeObjectAtIndex:i];
203-
} else {
204-
i++;
205-
}
206+
if (eventRegistration) {
207+
NSIndexSet *indexesToRemove =
208+
[self.eventRegistrations indexesOfObjectsPassingTest:^BOOL(
209+
id<FEventRegistration> existing,
210+
NSUInteger idx, BOOL *stop) {
211+
return [existing matches:eventRegistration];
212+
}];
213+
[self.eventRegistrations removeObjectsAtIndexes:indexesToRemove];
214+
} else {
215+
[self.eventRegistrations removeAllObjects];
206216
}
207-
} else {
208-
[self.eventRegistrations removeAllObjects];
209217
}
210218
return cancelEvents;
211219
}
@@ -270,7 +278,10 @@ - (NSArray *)generateEventsForChanges:(NSArray *)changes
270278
registration:(id<FEventRegistration>)registration {
271279
NSArray *registrations;
272280
if (registration == nil) {
273-
registrations = [[NSArray alloc] initWithArray:self.eventRegistrations];
281+
@synchronized(self.eventRegistrations) {
282+
registrations =
283+
[[NSArray alloc] initWithArray:self.eventRegistrations];
284+
}
274285
} else {
275286
registrations = [[NSArray alloc] initWithObjects:registration, nil];
276287
}

FirebaseDatabase/Tests/Integration/FIRDatabaseQueryTests.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,7 +3563,6 @@ - (void)testListenForChildAddedWithLimitEnsureEventsFireProperly {
35633563
WAIT_FOR(count == 3);
35643564
}
35653565

3566-
#ifdef FLAKY_TEST
35673566
- (void)testListenForChildChangedWithLimitEnsureEventsFireProperly {
35683567
FTupleFirebase* refs = [FTestHelpers getRandomNodePair];
35693568
FIRDatabaseReference* writer = refs.one;
@@ -3603,7 +3602,6 @@ - (void)testListenForChildChangedWithLimitEnsureEventsFireProperly {
36033602

36043603
WAIT_FOR(count == 3);
36053604
}
3606-
#endif
36073605

36083606
- (void)testListenForChildRemovedWithLimitEnsureEventsFireProperly {
36093607
FTupleFirebase* refs = [FTestHelpers getRandomNodePair];

0 commit comments

Comments
 (0)