I have been using NSPersistentContainer in my app and while, for the most part it works great, a growing percentage of my users are encountering crashes due to what looks like a database connection error when calling `performFetch()` on an `NSFetchedResultsController`.
fatal error: 'try!' expression unexpectedly raised an error:
Error Domain=NSCocoaErrorDomain
Code=134060 "A Core Data error occurred."
UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/1AD99C00-B61F-4BA5-B832-81DB8C486030/Library/Application Support/<redacted>.sqlite,
NSUnderlyingException=Attempted to perform an operation without an open database}:
file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-802.0.53/src/swift/stdlib/public/core/ErrorType.swift, line 182From what I can piece together from crash reports, it happens:
* Always after `container.loadPersistentStores` calls back successfully
* On both the `viewContext` and contexts generated by `newBackgroundContext()`
* Immediately on launch (though the app fetches data on launch so this is expected)
* In varying places -- I preload various screens and have a syncing engine which fetches in the background. Depeding on timing, the crash can occur in any of these places. Curiously, sometimes some fetches succeed before one fails and throws this error.
* All of a sudden for some users where it previously worked fine until then
Has anyone encountered this, or even this error message, before? Happy to provide any additional details as needed...
Thanks!