Browse Source

Replace TryGetValue/TryRemove by a single TryRemove call to avoid potential issues with concurrent cache removal/addition

pull/758/head
Kévin Chalet 7 years ago
parent
commit
f6aa21b46a
  1. 4
      src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs
  2. 4
      src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs
  3. 4
      src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs
  4. 4
      src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs

4
src/OpenIddict.Core/Caches/OpenIddictApplicationCache.cs

@ -378,11 +378,9 @@ namespace OpenIddict.Core
throw new InvalidOperationException("The application identifier cannot be extracted."); throw new InvalidOperationException("The application identifier cannot be extracted.");
} }
if (_signals.TryGetValue(identifier, out CancellationTokenSource signal)) if (_signals.TryRemove(identifier, out CancellationTokenSource signal))
{ {
signal.Cancel(); signal.Cancel();
_signals.TryRemove(identifier, out signal);
} }
} }

4
src/OpenIddict.Core/Caches/OpenIddictAuthorizationCache.cs

@ -596,11 +596,9 @@ namespace OpenIddict.Core
throw new InvalidOperationException("The application identifier cannot be extracted."); throw new InvalidOperationException("The application identifier cannot be extracted.");
} }
if (_signals.TryGetValue(identifier, out CancellationTokenSource signal)) if (_signals.TryRemove(identifier, out CancellationTokenSource signal))
{ {
signal.Cancel(); signal.Cancel();
_signals.TryRemove(identifier, out signal);
} }
} }

4
src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs

@ -349,11 +349,9 @@ namespace OpenIddict.Core
throw new InvalidOperationException("The application identifier cannot be extracted."); throw new InvalidOperationException("The application identifier cannot be extracted.");
} }
if (_signals.TryGetValue(identifier, out CancellationTokenSource signal)) if (_signals.TryRemove(identifier, out CancellationTokenSource signal))
{ {
signal.Cancel(); signal.Cancel();
_signals.TryRemove(identifier, out signal);
} }
} }

4
src/OpenIddict.Core/Caches/OpenIddictTokenCache.cs

@ -679,11 +679,9 @@ namespace OpenIddict.Core
throw new InvalidOperationException("The application identifier cannot be extracted."); throw new InvalidOperationException("The application identifier cannot be extracted.");
} }
if (_signals.TryGetValue(identifier, out CancellationTokenSource signal)) if (_signals.TryRemove(identifier, out CancellationTokenSource signal))
{ {
signal.Cancel(); signal.Cancel();
_signals.TryRemove(identifier, out signal);
} }
} }

Loading…
Cancel
Save