diff --git a/FirebaseRemoteConfig/CHANGELOG.md b/FirebaseRemoteConfig/CHANGELOG.md index 4d4beeb2c21..69c35d6e173 100644 --- a/FirebaseRemoteConfig/CHANGELOG.md +++ b/FirebaseRemoteConfig/CHANGELOG.md @@ -1,3 +1,6 @@ +# Unreleased +- [fixed] Fix Data Race on gIsNewDatabase. (#14715) + # 12.6.0 - [fixed] Fixed a bug where Remote Config does not work after a restore of a previous backup of the device. (#14459) diff --git a/FirebaseRemoteConfig/Sources/RCNConfigDBManager.m b/FirebaseRemoteConfig/Sources/RCNConfigDBManager.m index c1fd403a246..8b75d1aa7fa 100644 --- a/FirebaseRemoteConfig/Sources/RCNConfigDBManager.m +++ b/FirebaseRemoteConfig/Sources/RCNConfigDBManager.m @@ -120,12 +120,15 @@ @interface RCNConfigDBManager () { @implementation RCNConfigDBManager ++ (void)load { + gIsNewDatabaseQueue = dispatch_queue_create("com.google.FirebaseRemoteConfig.gIsNewDatabase", + DISPATCH_QUEUE_SERIAL); +} + + (instancetype)sharedInstance { static dispatch_once_t onceToken; static RCNConfigDBManager *sharedInstance; dispatch_once(&onceToken, ^{ - gIsNewDatabaseQueue = dispatch_queue_create("com.google.FirebaseRemoteConfig.gIsNewDatabase", - DISPATCH_QUEUE_SERIAL); sharedInstance = [[RCNConfigDBManager alloc] init]; }); return sharedInstance; diff --git a/FirebaseRemoteConfig/Tests/Unit/RCNConfigDBManagerTests.m b/FirebaseRemoteConfig/Tests/Unit/RCNConfigDBManagerTests.m new file mode 100644 index 00000000000..2a8812d0ea1 --- /dev/null +++ b/FirebaseRemoteConfig/Tests/Unit/RCNConfigDBManagerTests.m @@ -0,0 +1,41 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import "FirebaseRemoteConfig/Sources/RCNConfigDBManager.h" + +@interface RCNConfigDBManagerTests : XCTestCase +@end + +@implementation RCNConfigDBManagerTests + +- (void)testIsNewDatabaseThreadSafety { + RCNConfigDBManager *dbManager = [RCNConfigDBManager sharedInstance]; + XCTestExpectation *expectation = + [self expectationWithDescription:@"Concurrent access to isNewDatabase"]; + expectation.expectedFulfillmentCount = 100; + + for (int i = 0; i < 100; i++) { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + [dbManager isNewDatabase]; + [expectation fulfill]; + }); + } + + [self waitForExpectationsWithTimeout:5.0 handler:nil]; +} + +@end