From 0a5cb255b66e6c0c06d4a1727caf483ce586198b Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 11 Dec 2024 09:41:13 -0600 Subject: [PATCH] Cache and weakrefkey fixes --- .../Extensions/NewRelic.Agent.Extensions/Caching/LRUCache.cs | 4 ++-- .../NewRelic.Agent.Extensions/Caching/WeakReferenceKey.cs | 2 +- .../Providers/Wrapper/AwsSdk/AwsSdkPipelineWrapper.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Caching/LRUCache.cs b/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Caching/LRUCache.cs index 4d2c42377..9dc81d144 100644 --- a/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Caching/LRUCache.cs +++ b/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Caching/LRUCache.cs @@ -33,7 +33,7 @@ public LRUCache(int capacity) public TValue Get(TKey key) { - _lock.EnterReadLock(); + _lock.EnterUpgradeableReadLock(); try { if (_cacheMap.TryGetValue(key, out var node)) @@ -55,7 +55,7 @@ public TValue Get(TKey key) } finally { - _lock.ExitReadLock(); + _lock.ExitUpgradeableReadLock(); } } diff --git a/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Caching/WeakReferenceKey.cs b/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Caching/WeakReferenceKey.cs index b299961fa..478498fe5 100644 --- a/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Caching/WeakReferenceKey.cs +++ b/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Caching/WeakReferenceKey.cs @@ -11,7 +11,7 @@ namespace NewRelic.Agent.Extensions.Caching /// public class WeakReferenceKey where T : class { - public WeakReference WeakReference { get; } + private WeakReference WeakReference { get; } public WeakReferenceKey(T cacheKey) { diff --git a/src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AwsSdk/AwsSdkPipelineWrapper.cs b/src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AwsSdk/AwsSdkPipelineWrapper.cs index 6cadb8ccf..03e49fa48 100644 --- a/src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AwsSdk/AwsSdkPipelineWrapper.cs +++ b/src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AwsSdk/AwsSdkPipelineWrapper.cs @@ -54,10 +54,10 @@ private ArnBuilder CreateArnBuilder(IAgent agent, dynamic requestContext) return new ArnBuilder(partition, systemName, accountId); } - private string GetAccountId(IAgent agent, dynamic clientConfig) + private string GetAccountId(IAgent agent, object clientConfig) { var cacheKey = new WeakReferenceKey(clientConfig); - string accountId = AmazonServiceClientWrapper.AwsAccountIdByClientConfigCache.ContainsKey(cacheKey) ? (string)AmazonServiceClientWrapper.AwsAccountIdByClientConfigCache.Get(clientConfig) : agent.Configuration.AwsAccountId; + string accountId = AmazonServiceClientWrapper.AwsAccountIdByClientConfigCache.ContainsKey(cacheKey) ? AmazonServiceClientWrapper.AwsAccountIdByClientConfigCache.Get(cacheKey) : agent.Configuration.AwsAccountId; if (accountId != null) {