From 62782800b3be640df767ac669a0cc4564152f010 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 12 Nov 2021 13:02:20 -0300 Subject: [PATCH 1/4] Fix race in profile re-upload. --- SignalMessaging/profiles/OWSProfileManager.swift | 9 +-------- SignalMessaging/profiles/VersionedProfilesImpl.swift | 4 ++-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/SignalMessaging/profiles/OWSProfileManager.swift b/SignalMessaging/profiles/OWSProfileManager.swift index 320533be3f..79e4d9479a 100644 --- a/SignalMessaging/profiles/OWSProfileManager.swift +++ b/SignalMessaging/profiles/OWSProfileManager.swift @@ -302,14 +302,7 @@ extension OWSProfileManager { let promise = firstly { writeProfileAvatarToDisk(attempt: attempt) }.then(on: DispatchQueue.global()) { () -> Promise in - // Optimistically update local profile state. - databaseStorage.write { transaction in - self.updateLocalProfile(with: attempt, - userProfileWriter: userProfileWriter, - transaction: transaction) - } - - Logger.info("Versioned profile update.") + Logger.info("Versioned profile update, avatarUrlPath: \(attempt.avatarUrlPath?.nilIfEmpty != nil), avatarFilename: \(attempt.avatarFilename?.nilIfEmpty != nil)") return updateProfileOnServiceVersioned(attempt: attempt) }.done(on: DispatchQueue.global()) { _ in self.databaseStorage.write { (transaction: SDSAnyWriteTransaction) -> Void in diff --git a/SignalMessaging/profiles/VersionedProfilesImpl.swift b/SignalMessaging/profiles/VersionedProfilesImpl.swift index 34861e3019..122bf29b13 100644 --- a/SignalMessaging/profiles/VersionedProfilesImpl.swift +++ b/SignalMessaging/profiles/VersionedProfilesImpl.swift @@ -43,7 +43,7 @@ public class VersionedProfilesImpl: NSObject, VersionedProfilesSwift { profileAvatarData: Data?, unsavedRotatedProfileKey: OWSAES256Key?) -> Promise { - return DispatchQueue.global().async(.promise) { + firstly(on: .global()) { guard let localUuid = self.tsAccountManager.localUuid else { throw OWSAssertionError("Missing localUuid.") } @@ -54,7 +54,7 @@ public class VersionedProfilesImpl: NSObject, VersionedProfilesSwift { let profileKey: OWSAES256Key = unsavedRotatedProfileKey ?? self.profileManager.localProfileKey() return (localUuid, profileKey) - }.then(on: DispatchQueue.global()) { (localUuid: UUID, profileKey: OWSAES256Key) -> Promise in + }.then(on: .global()) { (localUuid: UUID, profileKey: OWSAES256Key) -> Promise in let localProfileKey = try self.parseProfileKey(profileKey: profileKey) let zkgUuid = try localUuid.asZKGUuid() let commitment = try localProfileKey.getCommitment(uuid: zkgUuid) From e25fd5940191b1346bc5b6cf3597f1b86ed8f5b2 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 12 Nov 2021 14:33:40 -0300 Subject: [PATCH 2/4] Improve profile update logging. --- SignalServiceKit/src/Util/OWSUserProfile.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Util/OWSUserProfile.m b/SignalServiceKit/src/Util/OWSUserProfile.m index 4b51f305a9..3eca2ff8af 100644 --- a/SignalServiceKit/src/Util/OWSUserProfile.m +++ b/SignalServiceKit/src/Util/OWSUserProfile.m @@ -744,7 +744,7 @@ NSString *NSStringForUserProfileWriter(UserProfileWriter userProfileWriter) @"%d), avatarUrlPathDidChange: %d (%d -> %d), " @"avatarFileNameDidChange: %d (%d -> %d), %@, %@.", profile.address, - profile.address.isLocalAddress, + [OWSUserProfile isLocalProfileAddress:profile.address], profileKeyDidChange, profileKeyBefore != nil, profile.profileKey != nil, From 98caa0bdfaa67fe7fc584bfb3f264912b347aee9 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 12 Nov 2021 14:48:38 -0300 Subject: [PATCH 3/4] Fix comment. --- SignalMessaging/profiles/OWSProfileManager.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/SignalMessaging/profiles/OWSProfileManager.swift b/SignalMessaging/profiles/OWSProfileManager.swift index 79e4d9479a..7f7ef11d01 100644 --- a/SignalMessaging/profiles/OWSProfileManager.swift +++ b/SignalMessaging/profiles/OWSProfileManager.swift @@ -9,7 +9,6 @@ public extension OWSProfileManager { // The main entry point for updating the local profile. It will: // - // * Update local state optimistically. // * Enqueue a service update. // * Attempt that service update. // From bb2ec48ed23b72ce9942779f8d1d48aa0271caa2 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Sat, 13 Nov 2021 17:12:11 -0300 Subject: [PATCH 4/4] Simplify profile re-upload. --- SignalServiceKit/src/Util/OWSUserProfile.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Util/OWSUserProfile.m b/SignalServiceKit/src/Util/OWSUserProfile.m index 3eca2ff8af..1b3b4f2c21 100644 --- a/SignalServiceKit/src/Util/OWSUserProfile.m +++ b/SignalServiceKit/src/Util/OWSUserProfile.m @@ -714,8 +714,9 @@ NSString *NSStringForUserProfileWriter(UserProfileWriter userProfileWriter) } } + BOOL isUpdatingDatabaseInstance = self != profile; if (shouldReupload && self.tsAccountManager.isPrimaryDevice - && CurrentAppContext().isMainApp) { + && CurrentAppContext().isMainApp && isUpdatingDatabaseInstance) { // shouldReuploadProtectedProfileName has side effects, // so only invoke it if shouldReupload is true. if (OWSUserProfile.shouldReuploadProtectedProfileName) {