IdentityModel
IdentityModel copied to clipboard
Synchronized the discovery document retrieving
As it was mentioned in #372 - DiscoveryCache is not thread-safe.
To prevent sending multiple Get request to discovery endpoint a simple binary Semaphore Slim synchronization was added.
@brockallen could you review for the 6.1 release?
The argument against is: simpler code is easier to maintain, I'm scared about deadlocks, and all consumers have to pay the cost of acquiring the lock even if they don't need thread safety.
I'm closing this PR for these reasons, and also because I believe that if you need a discovery cache guaranteed to only allow a single thread to make the discovery request, it should be possible to wrap the existing discovery cache in this kind of locking outside IdentityModel itself.
We could revisit this issue, especially if wrapping the cache with locks like I mention isn't feasible. If we were to do that, I'd like the locking to be in a new type, separate from the existing DiscoveryCache - a ConcurrentDiscoveryCache;.