apptentive / apptentive-kit-ios

ApptentiveKit SDK for iOS and iPadOS
https://www.apptentive.com
BSD 3-Clause "New" or "Revised" License
6 stars 3 forks source link

Migration from v5.3.4 to v6.0.6 breaks the integration #32

Closed ddanielczyk closed 1 year ago

ddanielczyk commented 1 year ago

We are migrating our app from 5.3.4 to 6.0.6 and the sdk is not working at all, constant errors about lack of Credentials and no request is actually made to the server.

I have tried to investigate it inside the library and it looks to me, that the flow is following:

  1. Apptentive.register(appCredentials:..)
  2. Backend.register(appCredentials:..)
  3. self.conversation.appCredentials = appCredentials (here correct credentials are set on Backend)
  4. Backend.start(appCredentials:...)
  5. Backend.startFilesAcces(..)
  6. CurrentLoader.loadLatestVersion
  7. try self.loadConversation(from: loader)

And we land in this method:

private func loadConversation(from loader: Loader) throws {
        let previousConversation = try loader.loadConversation() 

        self.conversationNeedsLoading = false
        self.lastSyncedConversation = previousConversation
        self.conversation = try previousConversation.merged(with: self.conversation)

        self.payloadSender.credentialsProvider = self.conversation
        self.syncConversationWithAPI()

        if self.conversation != previousConversation {
            self.conversationNeedsSaving = true
        }

        try self.saveConversationIfNeeded()
    }

The let previousConversation = try loader.loadConversation() loads a valid conversation from disk (I can see file exist on disk) - but this conversation has no credentials set.

Then it calls try previousConversation.merged(with: self.conversation) - and get in result a conversation with nil credentials, even thought the self.conversation had them before merge. So in short - old conversation have no credentials, new conversation have valid credentials, and the merge output instance have no credentials again. (I suspect the issue may be here, so that newer conversation credentials are not applied to older one, when merging).

And this output from above is assigned to self.conversation - hence from now on, provided app credentials are gone and it's not possible to get the SDK running.

NOTE: When doing a clean-install it works fine, so to me it's an issue with migration between old and new lib.

Some logs:

2022-11-08 16:26:00.112155+0100 hippo[7164:10649175] [PointsOfInterest] Deferring start until `register` is called.
2022-11-08 16:26:00.112285+0100 hippo[7164:10648863] [PointsOfInterest] Apptentive SDK Version 6.0.6 Initialized.
2022-11-08 16:26:00.114067+0100 hippo[7164:10648863] [PointsOfInterest] Setting person name to “----
2022-11-08 16:26:00.114235+0100 hippo[7164:10648863] [PointsOfInterest] Setting person email address to ---
2022-11-08 16:26:00.137690+0100 hippo[7164:10649175] [PointsOfInterest] Permanent failure when sending Payload(post to events): Missing app credentials (key and signature). Removing from queue.
2022-11-08 16:26:00.138020+0100 hippo[7164:10649175] [PointsOfInterest] Running periodic housekeeping task
2022-11-08 16:26:00.138207+0100 hippo[7164:10649175] [PointsOfInterest] Requesting new engagement manifest via Apptentive API (current one is absent or stale).
2022-11-08 16:26:00.138518+0100 hippo[7164:10649175] [PointsOfInterest] Requesting new app configuration via Apptentive API (current one is absent or stale).
2022-11-08 16:26:00.145059+0100 hippo[7164:10649175] [PointsOfInterest] Failed to download engagement manifest: Missing app credentials (key and signature).
2022-11-08 16:26:00.145230+0100 hippo[7164:10649175] [PointsOfInterest] Failed to download app configuration: Missing app credentials (key and signature).
2022-11-08 16:26:00.145399+0100 hippo[7164:10649175] [PointsOfInterest] Failed to download message list: Missing app credentials (key and signature)
2022-11-08 16:26:00.448142+0100 hippo[7164:10648863] [PointsOfInterest] Apptentive SDK registered successfully (existing conversation).
2022-11-08 16:26:00.448315+0100 hippo[7164:10648863] [PointsOfInterest] Apptentive SDK registered successfully (existing conversation).
2022-11-08 16:26:00.576008+0100 hippo[7164:10649191] [PointsOfInterest] Permanent failure when sending Payload(post to events): Missing app credentials (key and signature). Removing from queue.
2022-11-08 16:26:04.993251+0100 hippo[7164:10648863] [PointsOfInterest] Setting person custom data to ---
2022-11-08 16:26:11.131067+0100 hippo[7164:10649190] [PointsOfInterest] Running periodic housekeeping task
2022-11-08 16:26:11.131244+0100 hippo[7164:10649190] [PointsOfInterest] Requesting new engagement manifest via Apptentive API (current one is absent or stale).
2022-11-08 16:26:11.131698+0100 hippo[7164:10649190] [PointsOfInterest] Requesting new app configuration via Apptentive API (current one is absent or stale).
2022-11-08 16:26:11.135475+0100 hippo[7164:10649190] [PointsOfInterest] Failed to download engagement manifest: Missing app credentials (key and signature).
2022-11-08 16:26:11.135687+0100 hippo[7164:10649190] [PointsOfInterest] Failed to download app configuration: Missing app credentials (key and signature).
2022-11-08 16:26:11.135882+0100 hippo[7164:10649190] [PointsOfInterest] Failed to download message list: Missing app credentials (key and signature)
2022-11-08 16:26:20.134739+0100 hippo[7164:10649191] [PointsOfInterest] Running periodic housekeeping task
2022-11-08 16:26:20.135058+0100 hippo[7164:10649191] [PointsOfInterest] Requesting new engagement manifest via Apptentive API (current one is absent or stale).
2022-11-08 16:26:20.135725+0100 hippo[7164:10649191] [PointsOfInterest] Requesting new app configuration via Apptentive API (current one is absent or stale).
2022-11-08 16:26:20.136396+0100 hippo[7164:10649191] [PointsOfInterest] Failed to download engagement manifest: Missing app credentials (key and signature).
2022-11-08 16:26:20.136707+0100 hippo[7164:10649191] [PointsOfInterest] Failed to download app configuration: Missing app credentials (key and signature).
2022-11-08 16:26:20.136977+0100 hippo[7164:10649191] [PointsOfInterest] Failed to download message list: Missing app credentials (key and signature)
2022-11-08 16:26:23.511539+0100 hippo[7164:10649872] [PointsOfInterest] Permanent failure when sending Payload(post to events): Missing app credentials (key and signature). Removing from queue.
frankus commented 1 year ago

Thank you for the very detailed report. We'll be investigating this today and hope to get a fix out soon!

FONickReichard commented 1 year ago

Hey @frankus we experienced two similar crashes however it was on v6.0.4.

Background: Updating from v6.0.2 to v6.0.4.

1st crash

2 0  libswiftCore.dylib             0x39b74 _assertionFailure(_:_:file:line:flags:) + 308
3 1  libswiftCore.dylib             0x39e74 _isFastAssertConfiguration() + 102
4 2  [MY AP] .                      0xb52960 specialized Backend.register(appCredentials:completion:) + 498 (Apptentive.swift:498)
5 3  [MY AP]                       0xb405d8 partial apply for closure #2 in Apptentive.register(with:completion:) + 112 (<compiler-generated>:112)
6 4  [MY AP]                       0xb23cb8 thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:20)

crash_info_entry_0
2/Users/distiller/project/dd/SourcePackages/checkouts/apptentive-kit-ios/Sources/ApptentiveKit/Backend.swift:142: Fatal error: Mismatched Credentials: Please delete and reinstall the app

2nd crash

20  libswiftCore.dylib             0x37d7c _assertionFailure(_:_:file:line:flags:) + 312
31  libswiftCore.dylib             0x38080 _isFastAssertConfiguration() + 102
42                    0xbda4fc Conversation.merge(with:) + 916 (Conversation.swift:916)
53                    0xb4aa5c Backend.loadConversation(from:) + 108 (Conversation.swift:108)
64                    0xbc411c specialized static CurrentLoader.loadLatestVersion(containerURL:environment:completion:) + 197 (Backend.swift:197)
75                     0xb475d4 Backend.protectedDataDidBecomeAvailable(containerURL:cachesURL:environment:) + 1840 (<compiler-generated>:1840)
86                    0xb3c4f8 closure #1 in Apptentive.protectedDataDidBecomeAvailable(_:) + 431 (Apptentive.swift:431)
97                    0xb23cb8 thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:20)

crash_info_entry_0
/Users/distiller/project/dd/SourcePackages/checkouts/apptentive-kit-ios/Sources/ApptentiveKit/Model/Conversation.swift:79: Fatal error: Both new and existing conversations have tokens, but they do not match.

It looks like issue #31’s solution is to update to v6.0.6, however that leads issue #32.

Note: no crashes occurred when updating from v5.3.0 to v6.0.2.

frankus commented 1 year ago

This should be resolved in v6.0.7.

FONickReichard commented 1 year ago

Confirming v6.0.7 resolved the crash. Thank you @frankus