Always use inDatabase: in FMDatabaseQueue. Respect crashOnErrors for open #649
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_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 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
close
on anFMDatabaseQueue
and then callinDatabase:
and have the[self database]
fail to re-open the database and call the block with anil
db, which would break the nullability guarantee ofnonnull
as 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 addedcrashOnErrors
support to theopen
methods inFMDatabase
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-using
inDatabase:
everywhere. If that's the case, I'm open to refactoring this in a different way to accomplish the same goal. Thanks!