Optimize Token Refresh Synchronization in RefreshTokenDelegatingHandler to Reduce Unnecessary Lock Contention #127
Labels
area/identity-model-oidc-client
Issues related to Identity Model OIDC Client
The current implementation of
RefreshTokenDelegatingHandler
uses aSemaphoreSlim
to synchronize access to the access and refresh tokens. This synchronization strategy results in every token read being subjected to a lock, potentially leading to performance bottlenecks in high-concurrency environments.Suggested Enhancements
To address these issues, two main enhancements are proposed:
Implement ReaderWriterLockSlim for Token Access: Replace the
SemaphoreSlim
with aReaderWriterLockSlim
, which allows multiple concurrent reads of the access token without blocking, while still ensuring that token writes (refreshes) are exclusive and thread-safe. This change could significantly improve read performance by reducing contention.Potential Issue with ReaderWriterLockSlim: While this approach reduces read contention, it may still lead to multiple queued write requests if many threads simultaneously detect an expired token.
Single Active Refresh Operation: Implement a mechanism that ensures only one refresh operation is queued or in progress at a time. This could be achieved by:
Benefits
The text was updated successfully, but these errors were encountered: