From 9870f38f75fe512c9aad091244ccc173d6ce9e97 Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Fri, 6 Dec 2024 15:39:39 -0800 Subject: [PATCH 1/2] don't invoke installations from background queue --- .../Settings/SettingsDownloadClient.swift | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/FirebaseSessions/Sources/Settings/SettingsDownloadClient.swift b/FirebaseSessions/Sources/Settings/SettingsDownloadClient.swift index 66cda8defc0..f90cda8ef34 100644 --- a/FirebaseSessions/Sources/Settings/SettingsDownloadClient.swift +++ b/FirebaseSessions/Sources/Settings/SettingsDownloadClient.swift @@ -51,27 +51,31 @@ class SettingsDownloader: SettingsDownloadClient { return } - installations.installationID { result in - switch result { - case let .success(installationsInfo): - let request = self.buildRequest(url: validURL, fiid: installationsInfo.0) - let task = URLSession.shared.dataTask(with: request) { data, response, error in - if let data { - if let dict = try? JSONSerialization.jsonObject(with: data) as? [String: Any] { - completion(.success(dict)) - } else { - completion(.failure( - .JSONParseError("Failed to parse JSON to dictionary") - )) + DispatchQueue.main.async { + // Installation's FIRInstallationsIDController isn't thread-safe, so this has to go + // on the main thread. + self.installations.installationID { result in + switch result { + case let .success(installationsInfo): + let request = self.buildRequest(url: validURL, fiid: installationsInfo.0) + let task = URLSession.shared.dataTask(with: request) { data, response, error in + if let data { + if let dict = try? JSONSerialization.jsonObject(with: data) as? [String: Any] { + completion(.success(dict)) + } else { + completion(.failure( + .JSONParseError("Failed to parse JSON to dictionary") + )) + } + } else if let error { + completion(.failure(.URLSessionError(error.localizedDescription))) } - } else if let error { - completion(.failure(.URLSessionError(error.localizedDescription))) } + // Start the task that sends the network request + task.resume() + case let .failure(error): + completion(.failure(.InstallationIDError(error.localizedDescription))) } - // Start the task that sends the network request - task.resume() - case let .failure(error): - completion(.failure(.InstallationIDError(error.localizedDescription))) } } } From c505e8b7d98f2aa9534dda01296672ddf94450eb Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Fri, 6 Dec 2024 15:43:15 -0800 Subject: [PATCH 2/2] add changelogs --- Crashlytics/CHANGELOG.md | 3 +++ FirebasePerformance/CHANGELOG.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Crashlytics/CHANGELOG.md b/Crashlytics/CHANGELOG.md index 0f239714aab..4a9c90f2f1e 100644 --- a/Crashlytics/CHANGELOG.md +++ b/Crashlytics/CHANGELOG.md @@ -1,3 +1,6 @@ +# Unreleased +- [fixed] Fixed an issue where Installations was sometimes invoked off the main queue (#13961). + # 11.5.0 - [changed] Updated `upload-symbols` to version 3.19, removed all methods require CFRelease and switch to modern classes (#13420). diff --git a/FirebasePerformance/CHANGELOG.md b/FirebasePerformance/CHANGELOG.md index 6ac0cee960b..49f5d0974f7 100644 --- a/FirebasePerformance/CHANGELOG.md +++ b/FirebasePerformance/CHANGELOG.md @@ -1,3 +1,6 @@ +# Unreleased +- [fixed] Fixed an issue where Installations was sometimes invoked off the main queue (#13961). + # 11.6.0 - [fixed] Fix a crash related to registering for notifications when the app is between foreground or background states. (#13174)