Skip to content
Merged
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 FirebaseStorage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased
- [fixed] Fixed `InstanceCache` keying by bucket only, which caused named apps sharing a
storage bucket with the default app to use the wrong auth context. (#16039)

# 12.9.0
- [fixed] Fix "weak never mutated" build warning introduced in Xcode 26.2.

Expand Down
10 changes: 6 additions & 4 deletions FirebaseStorage/Sources/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ internal import FirebaseCoreExtension
private final class InstanceCache: @unchecked Sendable {
static let shared = InstanceCache()

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

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

if let instance = instances[bucket] {
let key = "\(app.name)|\(bucket)"
if let instance = instances[key] {
return instance
}
let newInstance = FirebaseStorage.Storage(app: app, bucket: bucket)
instances[bucket] = newInstance
instances[key] = newInstance
return newInstance
}
}
Expand Down
Loading