You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Always use inDatabase: in FMDatabaseQueue. Respect crashOnErrors for open - #649
In our code, we use a similar dispatch_get_specific technique 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 through inDatabase:, 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 close on an FMDatabaseQueue and then call inDatabase: and have the [self database] fail to re-open the database and call the block with a nil db, which would break the nullability guarantee of nonnull as described in FMDatabaseQueue.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 added crashOnErrors support to the open methods in FMDatabase to 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!
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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!