[iOS] Use serial queue for execution of iOS keychain operations #791
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.
Reason:
For iOS Keychain write function checks for existence of an item before performing changes, then it either:
This makes write not an atomic operation on the storage. For performing operation we are using
DispatchQueue.global(qos: .userInitiated)
, which returns concurrent queue. In case two concurrent writings happening on the same key, one of these may fail - checks for existence of entry for key, entry does not exist yet, tries to add new entry, but in the meantime concurrent write stores the entry and the add fails.Change:
This PR changes DispatchQueue used for executing iOS Keychain operations: Use serial queue instead of concurrent for execution of iOS keychain operations to avoid concurrent writing issues.
Background:
Before this plugin was using main DispatchQueue, which was serial as well, but it is suggested by Apple documentation not to use main Thread to avoid blocking of the UI. For details see this PR: #536