azure-activedirectory-identitymodel-extensions-for-dotnet icon indicating copy to clipboard operation
azure-activedirectory-identitymodel-extensions-for-dotnet copied to clipboard

Dispose SignatureProviders after moving to staging cache.

Open brentschmaltz opened this issue 1 month ago • 0 comments

This change solves a couple of issues.

  1. A race condition where a SignatureProvider was disposed but was still able to be obtained from the cache.
  2. SignatureProviders were not disposed when compacting, which results in a number of objects on the finalizer Q.

SignatureProviders are ref counted, but not removed and disposed when the ref count goes to zero. The logic is most likely the SignatureProvider will be used again in a short period.

The significant change is that on compaction SignatureProviders are moved to a 'compactCache'. Periodically, the 'compactCache' is examined for SignatureProviders that can be disposed.

The CryptoProviderFactory will never return a SignatureProvider from the 'compactCache' when asked to create a SignatureProvider.

SignatureProviders that were not cached, will be disposed when released.

It is helpful when reviewing, all tasks are run in serial on a background task.

brentschmaltz avatar Jul 03 '24 19:07 brentschmaltz