Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in save<Models> from DataStoreBaseBehavior #3716

Open
amruth-movano opened this issue May 22, 2024 · 5 comments
Open

Crash in save<Models> from DataStoreBaseBehavior #3716

amruth-movano opened this issue May 22, 2024 · 5 comments
Labels
bug Something isn't working datastore Issues related to the DataStore category

Comments

@amruth-movano
Copy link

Describe the bug

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

func save<M: Model>(_ 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
Copy link
Contributor

@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?

@phantumcode phantumcode added bug Something isn't working datastore Issues related to the DataStore category pending-community-response Issue is pending response from the issue requestor labels May 22, 2024
@amruth-movano
Copy link
Author

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

@github-actions github-actions bot removed the pending-community-response Issue is pending response from the issue requestor label May 27, 2024
@phantumcode
Copy link
Contributor

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

@phantumcode phantumcode added the pending-community-response Issue is pending response from the issue requestor label May 28, 2024
@amruth-movano
Copy link
Author

@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🎏) + 264
1 libswift_Concurrency.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

@github-actions github-actions bot added pending-maintainer-response Issue is pending response from an Amplify team member and removed pending-community-response Issue is pending response from the issue requestor labels Aug 26, 2024
@5d
Copy link
Member

5d commented Sep 3, 2024

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?

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working datastore Issues related to the DataStore category
Projects
None yet
Development

No branches or pull requests

3 participants