Skip to content

Commit 309707d

Browse files
authored
Make sure rollouts logging queue is not nil (#13058)
1 parent 02d963c commit 309707d

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

Crashlytics/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# # Unreleased
2+
- [fixed] Created a new queue for rollouts persistence writes and made sure rollouts logging queue is not nil while dispatching (#12913).
3+
14
# 10.27.0
25
- [added] Added support for catching the SIGTERM signal (#12881).
36
- [fixed] Fixed a hang when persisting Remote Config Rollouts to disk (#12913).

Crashlytics/Crashlytics/Controllers/FIRCLSRolloutsPersistenceManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
@interface FIRCLSRolloutsPersistenceManager : NSObject <FIRCLSPersistenceLog>
2727

28-
- (instancetype _Nullable)initWithFileManager:(FIRCLSFileManager *_Nonnull)fileManager;
28+
- (instancetype _Nullable)initWithFileManager:(FIRCLSFileManager *_Nonnull)fileManager
29+
andQueue:(dispatch_queue_t _Nonnull)queue;
2930
- (instancetype _Nonnull)init NS_UNAVAILABLE;
3031
+ (instancetype _Nonnull)new NS_UNAVAILABLE;
3132

Crashlytics/Crashlytics/Controllers/FIRCLSRolloutsPersistenceManager.m

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
#import <Foundation/Foundation.h>
16-
#include "Crashlytics/Crashlytics/Components/FIRCLSGlobals.h"
1716
#include "Crashlytics/Crashlytics/Components/FIRCLSUserLogging.h"
1817
#import "Crashlytics/Crashlytics/Helpers/FIRCLSLogger.h"
1918
#import "Crashlytics/Crashlytics/Models/FIRCLSFileManager.h"
@@ -32,15 +31,23 @@
3231

3332
@interface FIRCLSRolloutsPersistenceManager : NSObject <FIRCLSPersistenceLog>
3433
@property(nonatomic, readonly) FIRCLSFileManager *fileManager;
34+
@property(nonnull, nonatomic, readonly) dispatch_queue_t rolloutsLoggingQueue;
3535
@end
3636

3737
@implementation FIRCLSRolloutsPersistenceManager
38-
- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager {
38+
- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
39+
andQueue:(dispatch_queue_t)queue {
3940
self = [super init];
4041
if (!self) {
4142
return nil;
4243
}
4344
_fileManager = fileManager;
45+
46+
if (!queue) {
47+
FIRCLSDebugLog(@"Failed to intialize FIRCLSRolloutsPersistenceManager, logging queue is nil");
48+
return nil;
49+
}
50+
_rolloutsLoggingQueue = queue;
4451
return self;
4552
}
4653

@@ -57,7 +64,11 @@ - (void)updateRolloutsStateToPersistenceWithRollouts:(NSData *_Nonnull)rollouts
5764

5865
NSFileHandle *rolloutsFile = [NSFileHandle fileHandleForUpdatingAtPath:rolloutsPath];
5966

60-
dispatch_async(FIRCLSGetLoggingQueue(), ^{
67+
if (!_rolloutsLoggingQueue) {
68+
FIRCLSDebugLog(@"Rollouts logging queue is dealloccated");
69+
}
70+
71+
dispatch_async(_rolloutsLoggingQueue, ^{
6172
@try {
6273
[rolloutsFile seekToEndOfFile];
6374
NSMutableData *rolloutsWithNewLineData = [rollouts mutableCopy];

Crashlytics/Crashlytics/FIRCrashlytics.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ - (instancetype)initWithApp:(FIRApp *)app
211211
FIRCLSDebugLog(@"Registering RemoteConfig SDK subscription for rollouts data");
212212

213213
FIRCLSRolloutsPersistenceManager *persistenceManager =
214-
[[FIRCLSRolloutsPersistenceManager alloc] initWithFileManager:_fileManager];
214+
[[FIRCLSRolloutsPersistenceManager alloc]
215+
initWithFileManager:_fileManager
216+
andQueue:dispatch_queue_create(
217+
"com.google.firebase.FIRCLSRolloutsPersistence",
218+
DISPATCH_QUEUE_SERIAL)];
215219
_remoteConfigManager =
216220
[[FIRCLSRemoteConfigManager alloc] initWithRemoteConfig:remoteConfig
217221
persistenceDelegate:persistenceManager];

Crashlytics/UnitTests/FIRCLSRolloutsPersistenceManagerTests.m

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
@interface FIRCLSRolloutsPersistenceManagerTests : XCTestCase
3232
@property(nonatomic, strong) FIRCLSTempMockFileManager *fileManager;
33+
@property(nonatomic, strong) dispatch_queue_t loggingQueue;
3334
@property(nonatomic, strong) FIRCLSRolloutsPersistenceManager *rolloutsPersistenceManager;
3435
@end
3536

@@ -41,8 +42,11 @@ - (void)setUp {
4142
[self.fileManager createReportDirectories];
4243
[self.fileManager setupNewPathForExecutionIdentifier:reportId];
4344

45+
self.loggingQueue =
46+
dispatch_queue_create("com.google.firebase.FIRCLSRolloutsPersistence", DISPATCH_QUEUE_SERIAL);
4447
self.rolloutsPersistenceManager =
45-
[[FIRCLSRolloutsPersistenceManager alloc] initWithFileManager:self.fileManager];
48+
[[FIRCLSRolloutsPersistenceManager alloc] initWithFileManager:self.fileManager
49+
andQueue:self.loggingQueue];
4650
}
4751

4852
- (void)tearDown {
@@ -65,18 +69,22 @@ - (void)testUpdateRolloutsStateToPersistenceWithRollouts {
6569
NSString *rolloutsFilePath =
6670
[[[self.fileManager activePath] stringByAppendingPathComponent:reportId]
6771
stringByAppendingPathComponent:FIRCLSReportRolloutsFile];
68-
6972
[self.rolloutsPersistenceManager updateRolloutsStateToPersistenceWithRollouts:data
7073
reportID:reportId];
71-
74+
XCTAssertNotNil(self.loggingQueue);
7275
// Wait for the logging queue to finish.
73-
dispatch_async(FIRCLSGetLoggingQueue(), ^{
76+
dispatch_async(self.loggingQueue, ^{
7477
[expectation fulfill];
7578
});
7679

7780
[self waitForExpectations:@[ expectation ] timeout:3];
7881

7982
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:rolloutsFilePath]);
83+
84+
NSFileHandle *rolloutsFile = [NSFileHandle fileHandleForUpdatingAtPath:rolloutsFilePath];
85+
NSData *fileData = [rolloutsFile readDataToEndOfFile];
86+
NSString *fileString = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];
87+
XCTAssertTrue([fileString isEqualToString:[encodedStateString stringByAppendingString:@"\n"]]);
8088
}
8189

8290
- (void)testUpdateRolloutsStateToPersistenceEnsureNoHang {
@@ -93,7 +101,7 @@ - (void)testUpdateRolloutsStateToPersistenceEnsureNoHang {
93101

94102
// Clog up the queue with a long running operation. This sleep time
95103
// must be longer than the expectation timeout.
96-
dispatch_async(FIRCLSGetLoggingQueue(), ^{
104+
dispatch_async(self.loggingQueue, ^{
97105
sleep(10);
98106
});
99107

0 commit comments

Comments
 (0)