Deadlock while using Factory DI #345
pstarunuce
started this conversation in
General
Replies: 1 comment
-
|
Don't do that??? And I mean that semi-seriously. I tend to frown on doing any heavy lifting in the class initializer, and that most definitely applies to acquiring sync locks. Not sure how to solve your particular case, exactly, But I'd look at lazy initialization, or doing some sort of two-stage initialization tied to lifecycle events and not associated with object creation. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
IssueWe encountered an application deadlock stemming from a threading conflict. The Core Data stack initialization, running on a background thread, is attempting to acquire a lock. Concurrently, another task (running on the main thread) is resolving a different dependency and is waiting for the Core Data initialization to complete, which is blocking the main thread because the Core Data initialization task has already acquired the lock. The likely cause of the deadlock is that the
https://developer.apple.com/documentation/coredata/nspersistentcontainer/loadpersistentstores(completionhandler:) method, which is called during Core Data initialization, requires the main thread to complete its work, but the main thread is already blocked.
Steps to reproduce
Here is a simple example to recreate the same issue:
I need suggestions on how to avoid these deadlocks.
Beta Was this translation helpful? Give feedback.
All reactions