Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Crashlytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Unreleased
- [fixed] Fixed a thread-safety issue where stored on-demand exception paths
could be accessed concurrently from multiple queues when data collection is
disabled, and ensured queued on-demand exceptions re-check consent after
rate-limiting delays and are cleaned up by `deleteUnsentReports()`. (#16805)
- [fixed] Fixed two Swift concurrency warnings in Firebase Sessions when
building for watchOS with Xcode 27. (#17119)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ - (void)sendUnsentReportsWithToken:(FIRCLSDataCollectionToken *)dataCollectionTo
asUrgent:urgent];
}

for (NSString *path in self.onDemandModel.storedActiveReportPaths) {
NSArray<NSString *> *storedOnDemandPaths = [self.onDemandModel takeStoredActiveReportPaths];
for (NSString *path in storedOnDemandPaths) {
[self processExistingActiveReportPath:path
dataCollectionToken:dataCollectionToken
asUrgent:urgent];
}
[self.onDemandModel.storedActiveReportPaths removeAllObjects];

// deal with stuff in processing more carefully - do not process again
[self.operationQueue addOperationWithBlock:^{
Expand Down Expand Up @@ -241,8 +241,11 @@ - (void)processExistingActiveReportPath:(NSString *)path
}

- (void)deleteUnsentReports {
NSArray<NSString *> *storedOnDemandPaths =
[self.onDemandModel takeStoredActiveReportPaths] ?: @[];
NSArray<NSString *> *reportPaths = @[];
reportPaths = [reportPaths arrayByAddingObjectsFromArray:self.existingUnemptyActiveReportPaths];
reportPaths = [reportPaths arrayByAddingObjectsFromArray:storedOnDemandPaths];
reportPaths = [reportPaths arrayByAddingObjectsFromArray:self.processingReportPaths];
reportPaths = [reportPaths arrayByAddingObjectsFromArray:self.preparedReportPaths];

Expand Down
3 changes: 1 addition & 2 deletions Crashlytics/Crashlytics/FIRCrashlytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,7 @@ - (void)recordOnDemandExceptionModel:(FIRExceptionModel *)exceptionModel {
callback:^{
[self.managerData.onDemandModel
recordOnDemandExceptionIfQuota:copiedModel
withDataCollectionEnabled:[self.dataArbiter
isCrashlyticsCollectionEnabled]
withDataArbiter:self.dataArbiter
usingExistingReportManager:self.existingReportManager];
}];
}
Expand Down
41 changes: 33 additions & 8 deletions Crashlytics/Crashlytics/Models/FIRCLSOnDemandModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ @interface FIRCLSOnDemandModel ()
@property(nonatomic) double currentStep;

@property(nonatomic, strong) FIRCLSFileManager *fileManager;
@property(nonatomic, strong) NSMutableArray *storedActiveReportPaths;
@property(nonatomic, strong, readonly) NSMutableArray<NSString *> *storedActiveReportPaths;

@end

Expand Down Expand Up @@ -78,7 +78,7 @@ - (instancetype)initWithFIRCLSSettings:(FIRCLSSettings *)settings
_lastUpdated = [NSDate timeIntervalSinceReferenceDate];
_currentStep = -1;

self.storedActiveReportPaths = [NSMutableArray array];
_storedActiveReportPaths = [NSMutableArray array];

return self;
}
Expand All @@ -88,7 +88,7 @@ - (instancetype)initWithFIRCLSSettings:(FIRCLSSettings *)settings
* rate limiting and exponential backoff.
*/
- (BOOL)recordOnDemandExceptionIfQuota:(FIRExceptionModel *)exceptionModel
withDataCollectionEnabled:(BOOL)dataCollectionEnabled
withDataArbiter:(FIRCLSDataCollectionArbiter *)dataArbiter
usingExistingReportManager:(FIRCLSExistingReportManager *)existingReportManager {
// Record the exception model into a new report if there is unused on-demand quota. Otherwise,
// log the occurrence but drop the event.
Expand Down Expand Up @@ -118,16 +118,15 @@ - (BOOL)recordOnDemandExceptionIfQuota:(FIRExceptionModel *)exceptionModel
[self.operationQueue addOperationWithBlock:^{
double uploadDelay = [self calculateUploadDelay];

if (dataCollectionEnabled) {
if ([dataArbiter isCrashlyticsCollectionEnabled]) {
[existingReportManager handleOnDemandReportUpload:activeReportPath
dataCollectionToken:dataCollectionToken
asUrgent:YES];
FIRCLSDebugLog(@"Submitted an on-demand exception, starting delay %.20f", uploadDelay);
} else {
[self.storedActiveReportPaths insertObject:activeReportPath atIndex:0];
if ([self.storedActiveReportPaths count] > FIRCLSMaxUnsentReports) {
[self.fileManager removeItemAtPath:[self.storedActiveReportPaths lastObject]];
[self.storedActiveReportPaths removeLastObject];
NSString *evictedPath = [self storeActiveReportPath:activeReportPath];
if (evictedPath) {
[self.fileManager removeItemAtPath:evictedPath];
[self decrementRecordedExceptionCount];
[self incrementDroppedExceptionCount];
}
Expand All @@ -140,6 +139,32 @@ - (BOOL)recordOnDemandExceptionIfQuota:(FIRExceptionModel *)exceptionModel
}
}

- (NSArray<NSString *> *)takeStoredActiveReportPaths {
@synchronized(_storedActiveReportPaths) {
NSArray<NSString *> *paths = [_storedActiveReportPaths copy];
[_storedActiveReportPaths removeAllObjects];
return paths;
}
}

- (NSArray<NSString *> *)storedActiveReportPathsSnapshot {
@synchronized(_storedActiveReportPaths) {
return [_storedActiveReportPaths copy];
}
}

- (NSString *)storeActiveReportPath:(NSString *)activeReportPath {
@synchronized(_storedActiveReportPaths) {
[_storedActiveReportPaths insertObject:activeReportPath atIndex:0];
if ([_storedActiveReportPaths count] > FIRCLSMaxUnsentReports) {
NSString *evictedPath = [_storedActiveReportPaths lastObject];
[_storedActiveReportPaths removeLastObject];
return evictedPath;
}
return nil;
}
}

- (double)calculateUploadDelay {
double calculatedStepDuration = [self calculateStepDuration];
double power = pow(self.settings.onDemandBackoffBase, calculatedStepDuration);
Expand Down
13 changes: 8 additions & 5 deletions Crashlytics/Crashlytics/Private/FIRCLSOnDemandModel_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,25 @@
#import "Crashlytics/Crashlytics/Private/FIRCLSExistingReportManager_Private.h"
#import "Crashlytics/Crashlytics/Private/FIRExceptionModel_Private.h"

@class FIRCLSDataCollectionArbiter;

@interface FIRCLSOnDemandModel (Private)

- (instancetype)initWithFIRCLSSettings:(FIRCLSSettings *)settings
fileManager:(FIRCLSFileManager *)fileManager;

- (BOOL)recordOnDemandExceptionIfQuota:(FIRExceptionModel *)exceptionModel
withDataCollectionEnabled:(BOOL)dataCollectionEnabled
withDataArbiter:(FIRCLSDataCollectionArbiter *)dataArbiter
usingExistingReportManager:(FIRCLSExistingReportManager *)existingReportManager;

- (int)getQueuedOperationsCount;
- (void)setQueuedOperationsCount:(int)count;

// When data collection is off, stores active paths that have been recorded but not dispatched for
// upload. Kept sorted (newest at front) so that we can limit on-device reports to the newest
// `FIRCLSMaxUnsentReports` reports.
@property(nonatomic, strong) NSMutableArray *storedActiveReportPaths;
// Returns a copy of the stored active report paths and removes the original.
- (NSArray<NSString *> *)takeStoredActiveReportPaths;

// Returns a copy of the currently stored active report paths without removing them.
- (NSArray<NSString *> *)storedActiveReportPathsSnapshot;

@property(nonatomic, readonly) int recordedOnDemandExceptionCount;
@property(nonatomic, readonly) int droppedOnDemandExceptionCount;
Expand Down
Loading
Loading