Skip to content

Commit d962bd5

Browse files
authored
Storage lock fix (#10468)
* Revert "Include subheaders in script output (#10212)" This reverts commit 11313da. * Use a dedicated sync object * Revert "Revert "Include subheaders in script output (#10212)"" This reverts commit 41fe302. * Add changelog and tests * Revert "Include subheaders in script output (#10212)" This reverts commit 11313da. * Revert "Revert "Include subheaders in script output (#10212)"" This reverts commit 472e3f9. * style
1 parent 29e9416 commit d962bd5

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

FirebaseStorage/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# 10.2.0
2-
- [fixed] Fix a race condition where a download size could exceed the value of the `maxSize` parameter. (#10358)
2+
- [fixed] Fixed an issue where using Storage with more than one FirebaseApp instance caused non-default Storage instances to deadlock (#10463).
3+
- [fixed] Fixed a race condition where a download size could exceed the value of the `maxSize` parameter. (#10358)
34

45
# 10.1.0
56
- [fixed] Fixed a 10.0.0 regression where metadata passed to `putFile` was not properly initialized. (#10353)

FirebaseStorage/Sources/Storage.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ import FirebaseAuthInterop
302302
}
303303

304304
/// Map of apps to a dictionary of buckets to GTMSessionFetcherService.
305+
private static let fetcherServiceLock = NSObject()
305306
private static var fetcherServiceMap: [String: [String: GTMSessionFetcherService]] = [:]
306307
private static var retryWhenOffline: GTMSessionFetcherRetryBlock = {
307308
(suggestedWillRetry: Bool,
@@ -321,8 +322,8 @@ import FirebaseAuthInterop
321322
_ auth: AuthInterop,
322323
_ appCheck: AppCheckInterop)
323324
-> GTMSessionFetcherService {
324-
objc_sync_enter(fetcherServiceMap)
325-
defer { objc_sync_exit(fetcherServiceMap) }
325+
objc_sync_enter(fetcherServiceLock)
326+
defer { objc_sync_exit(fetcherServiceLock) }
326327
var bucketMap = fetcherServiceMap[app.name]
327328
if bucketMap == nil {
328329
bucketMap = [:]

FirebaseStorage/Tests/Integration/StorageIntegration.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ class StorageResultTests: StorageIntegrationCommon {
137137
waitForExpectations()
138138
}
139139

140+
func testNoDeadlocks() throws {
141+
let storage2 = Storage.storage(url: "")
142+
143+
let expectation1 = expectation(description: #function)
144+
let expectation2 = expectation(description: #function)
145+
let ref = storage.reference(withPath: "ios/public/testBytesUpload")
146+
let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed")
147+
ref.putData(data) { result in
148+
expectation1.fulfill()
149+
150+
let ref2 = storage2.reference(withPath: "ios/public/testBytesUpload")
151+
ref2.putData(data) { result in
152+
expectation2.fulfill()
153+
}
154+
}
155+
waitForExpectations(timeout: 30)
156+
}
157+
140158
func testSimplePutSpecialCharacter() throws {
141159
let expectation = self.expectation(description: #function)
142160
let ref = storage.reference(withPath: "ios/public/-._~!$'()*,=:@&+;")

0 commit comments

Comments
 (0)