Always use inDatabase: in FMDatabaseQueue. Respect crashOnErrors for open#649
Always use inDatabase: in FMDatabaseQueue. Respect crashOnErrors for open#649benasher44 wants to merge 1 commit into
Conversation
|
Would this help a crash I am getting using the database queue from my main thread? It only happens sometimes. It's a background thread that is crashing. I know I could use a dispatch queue from the main thread, but also that blocking should work fine. libobjc.A.dylib |
|
您的邮件已经收到,我会尽快查阅,谢谢!Best Wishes!
|
In our code, we use a similar
dispatch_get_specifictechnique to guard against deadlock. When I realized this, I was hoping I could just use what's built into FMDB instead. However, It appears not all calls go throughinDatabase:, which means those other calls could deadlock un-knowlingly (or at least without making much noise).In doing that, I also realized that you could conceivably call
closeon anFMDatabaseQueueand then callinDatabase:and have the[self database]fail to re-open the database and call the block with anildb, which would break the nullability guarantee ofnonnullas described inFMDatabaseQueue.h. This isn't a big deal in Obj-C, but in Swift it'll cause crash. I fixed it to bail out early and not call the block if the re-open fails. I also addedcrashOnErrorssupport to theopenmethods inFMDatabaseto make this scenario hard to miss in debug.After writing this, it occurs to me that there could have been some reason for not
re-usinginDatabase:everywhere. If that's the case, I'm open to refactoring this in a different way to accomplish the same goal. Thanks!