Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lock to improve concurrency usage #68

Merged
merged 6 commits into from Oct 30, 2017
Merged

add lock to improve concurrency usage #68

merged 6 commits into from Oct 30, 2017

Conversation

ahernandezlopez
Copy link
Contributor

@ahernandezlopez ahernandezlopez commented Oct 27, 2017

TL;DR

  • add lock to improve concurrency usage
  • added tests to check concurrency usage is correct

The change is motivated because we found a crash in the letgo app (using keychain-swift). We found out that the reason is accessing the keychain concurrently from two threads. The crash is happening in getData method when calling SecItemCopyMatching.

We implemented some tests in ConcurrencyTests.swift. If removing the NSLock usage and running them you'll see the above mentioned crash. Contribution by @elikohen

@evgenyneu
Copy link
Owner

Hi, thanks for contributing. A couple of questions:

  • What motivated this change? Did it crash without the lock?
  • How safe is it to use NSLock? Is it possible that it will create dead locks?

@ahernandezlopez
Copy link
Contributor Author

ahernandezlopez commented Oct 30, 2017

Hi! Thanks! The contribution is by @elikohen so credit is for him ;) We have this improvement in our fork so I thought it would be nicer to have it in the main repo.

About your questions:

  1. The change is motivated because we found a crash in the letgo app (using keychain-swift). We found out that the reason is accessing the keychain concurrently from two threads. The crash is happening in getData method when calling SecItemCopyMatching. Yes, it crashes without the lock. You will be able to see the crash when running ConcurrencyTests.swift.
  2. It is safe. We lock at the beginning of the method and always unlock using a defer clause. Currently, it is not possible to create a dead lock as the only place to acquire the lock is in that method.

@ahernandezlopez
Copy link
Contributor Author

Updated PR description :)

@evgenyneu evgenyneu merged commit b0644f1 into evgenyneu:master Oct 30, 2017
@ahernandezlopez
Copy link
Contributor Author

Thanks @evgenyneu!

@evgenyneu
Copy link
Owner

Thanks for awesome fix @elikohen and @ahernandezlopez! I've released it in version 10 to cocoapods.

@ahernandezlopez
Copy link
Contributor Author

Cool! Thanks!!!

@ahernandezlopez ahernandezlopez deleted the evgenyneu-master branch March 21, 2018 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants