Skip to content

Commit cb4c3ba

Browse files
llamingtonncooke3
authored andcommitted
fix(storage): key InstanceCache by app name and bucket (#16039) (#16040)
1 parent b2ef0a2 commit cb4c3ba

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

FirebaseStorage/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Unreleased
2+
- [fixed] Fixed `InstanceCache` keying by bucket only, which caused named apps sharing a
3+
storage bucket with the default app to use the wrong auth context. (#16039)
4+
15
# 12.9.0
26
- [fixed] Fix "weak never mutated" build warning introduced in Xcode 26.2.
37

FirebaseStorage/Sources/Storage.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,9 @@ internal import FirebaseCoreExtension
244244
private final class InstanceCache: @unchecked Sendable {
245245
static let shared = InstanceCache()
246246

247-
/// A map of active instances, grouped by app. Keys are FirebaseApp names and values are
248-
/// instances of Storage associated with the given app.
247+
/// A map of active instances, grouped by app and bucket. Keys combine the
248+
/// FirebaseApp name and bucket to ensure each app gets its own Storage
249+
/// instance, even when multiple apps share the same storage bucket.
249250
private var instances: [String: Storage] = [:]
250251

251252
/// Lock to manage access to the instances array to avoid race conditions.
@@ -257,11 +258,12 @@ internal import FirebaseCoreExtension
257258
os_unfair_lock_lock(&instancesLock)
258259
defer { os_unfair_lock_unlock(&instancesLock) }
259260

260-
if let instance = instances[bucket] {
261+
let key = "\(app.name)|\(bucket)"
262+
if let instance = instances[key] {
261263
return instance
262264
}
263265
let newInstance = FirebaseStorage.Storage(app: app, bucket: bucket)
264-
instances[bucket] = newInstance
266+
instances[key] = newInstance
265267
return newInstance
266268
}
267269
}

0 commit comments

Comments
 (0)