aws-amplify / amplify-swift

A declarative library for application development using cloud services.
Apache License 2.0
447 stars 193 forks source link

Crash in save<Models> from DataStoreBaseBehavior #3716

Open amruth-movano opened 3 months ago

amruth-movano commented 3 months ago

Describe the bug

Hi Team, Today I got crash while running the ios app. The crash was in extension class DataStoreBaseBehavior-

func save(_ models: [M], where predicate: QueryPredicate?) async throws -> [M] { let results = try await withThrowingTaskGroup(of: M.self) { group in for model in models { group.addTask { try await save(model, where: predicate) // Crash line } }

        return try await group.reduce(into: []) { array, model in
            array.append(model)
        }
    }

    return results
}

Steps To Reproduce

I got it on app launch.

Crash error - 

Thread 94: Fatal error: SWIFT TASK CONTINUATION MISUSE: save(_:modelSchema:where:) tried to resume its continuation more than once, throwing DataStoreError: The operation couldn’t be completed. (SQLite.Result error 0.)
Recovery suggestion: The operation couldn’t be completed. (SQLite.Result error 0.)
Caused by:
cannot rollback - no transaction is active (code: 1)!

Expected behavior

App should not crash in save models

Amplify Framework Version

2.33.6

Amplify Categories

DataStore

Dependency manager

Swift PM

Swift version

5.9.2

CLI version

12.11.1

Xcode version

15.2

Relevant log output

Thread 94: Fatal error: SWIFT TASK CONTINUATION MISUSE: save(_:modelSchema:where:) tried to resume its continuation more than once, throwing DataStoreError: The operation couldn’t be completed. (SQLite.Result error 0.)
Recovery suggestion: The operation couldn’t be completed. (SQLite.Result error 0.)
Caused by:
cannot rollback - no transaction is active (code: 1)!

Is this a regression?

No

Regression additional context

No response

Platforms

iOS

OS Version

iOS 17.5

Device

iPhone 15 Plus

Specific to simulators

No response

Additional context

No response

phantumcode commented 3 months ago

@amruth-movano Thanks for submitting your issue. To help reduce produce the issue, can you provide your model/schema and the request parameters that resulted in the crash?

amruth-movano commented 3 months ago

@phantumcode Hi, currently it is not reproducible, so not sure how can I help wth parameters which were resulted in crash

phantumcode commented 3 months ago

@amruth-movano Are you able to provide your model schema or a example schema or test app that can help reproduce the issue?

amruth-movano commented 3 weeks ago

@phantumcode I am not getting it while debugging, its from firebase now. Below is the crash logs -

      Crashed: com.apple.root.user-initiated-qos.cooperative

0 libswiftCore.dylib 0x38870 assertionFailure(:_:file:line:flags:) + 264 1 libswiftConcurrency.dylib 0x5b80 CheckedContinuation.resume(throwing:) + 472 2 Evie Ring 0x85ea88 CheckedContinuation.resume(with:) + 4348406408 (:4348406408) 3 Evie Ring 0x85e7ec closure #1 in closure #1 in AWSDataStorePlugin.save(:modelSchema:where:) + 66 (AWSDataStorePlugin+DataStoreBaseBehavior.swift:66) 4 Evie Ring 0x85e2dc closure #2 in AWSDataStorePlugin.save(:modelSchema:where:completion:) + 54 (AWSDataStorePlugin+DataStoreBaseBehavior.swift:54) 5 Evie Ring 0x8b1c28 closure #1 in StorageEngine.syncMutation(of:modelSchema:mutationType:predicate:syncEngine:completion:) + 382 (StorageEngine.swift:382) 6 Evie Ring 0x8d84b4 closure #1 in AWSMutationDatabaseAdapter.save(mutationEvent:storageAdapter:completionPromise:) + 230 (AWSMutationDatabaseAdapter+MutationEventIngester.swift:230) 7 Evie Ring 0x8a6dbc SQLiteStorageEngineAdapter.save(:modelSchema:condition:eagerLoad:completion:) + 155 (StorageEngineAdapter+SQLite.swift:155) 8 Evie Ring 0x8a6cc8 SQLiteStorageEngineAdapter.save(:condition:eagerLoad:completion:) + 139 (StorageEngineAdapter+SQLite.swift:139) 9 Evie Ring 0x8aac74 protocol witness for ModelStorageBehavior.save(:condition:eagerLoad:completion:) in conformance SQLiteStorageEngineAdapter + 4348718196 (:4348718196) 10 Evie Ring 0x8d7f90 AWSMutationDatabaseAdapter.save(mutationEvent:storageAdapter:completionPromise:) + 213 (AWSMutationDatabaseAdapter+MutationEventIngester.swift:213) 11 Evie Ring 0x8d6a78 AWSMutationDatabaseAdapter.resolve(candidate:localEvents:per:storageAdapter:completionPromise:) + 189 (AWSMutationDatabaseAdapter+MutationEventIngester.swift:189) 12 Evie Ring 0x8d5f40 closure #1 in AWSMutationDatabaseAdapter.resolveConflictsThenSave(mutationEvent:storageAdapter:completion:) + 45 (AWSMutationDatabaseAdapter+MutationEventIngester.swift:45) 13 Evie Ring 0x92e670 closure #1 in static MutationEvent.pendingMutationEvents(for:storageAdapter:completion:) + 95 (MutationEvent+Query.swift:95) 14 libswift_Concurrency.dylib 0x41c2c swift::runJobInEstablishedExecutorContext(swift::Job) + 416 15 libswift_Concurrency.dylib 0x42e88 swift_job_runImpl(swift::Job, swift::ExecutorRef) + 72 16 libdispatch.dylib 0x15be4 _dispatch_root_queue_drain + 392 17 libdispatch.dylib 0x163ec _dispatch_worker_thread2 + 156 18 libsystem_pthread.dylib 0x1928 _pthread_wqthread + 228 19 libsystem_pthread.dylib 0x1a04 start_wqthread + 8

5d commented 2 weeks ago

We addressed a similar issue in #3595, with the patch released in version 2.29.1. We'll investigate this further, but could you also double confirm the version associated with the crash log?