Skip to content

Commit ae1d422

Browse files
authored
fix: Remove usage of non-thread safe HashSet in AwsSdk pipeline wrappers. Thanks, @gjunge! (#2855) (#2857)
1 parent e77683b commit ae1d422

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AwsSdk/AwsSdkPipelineWrapper.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Collections.Generic;
55
using NewRelic.Agent.Api;
6+
using NewRelic.Agent.Extensions.Collections;
67
using NewRelic.Agent.Extensions.Providers.Wrapper;
78

89
namespace NewRelic.Providers.Wrapper.AwsSdk
@@ -12,7 +13,7 @@ public class AwsSdkPipelineWrapper : IWrapper
1213
public bool IsTransactionRequired => true;
1314

1415
private const string WrapperName = "AwsSdkPipelineWrapper";
15-
private static HashSet<string> _unsupportedRequestTypes = new();
16+
private static ConcurrentHashSet<string> _unsupportedRequestTypes = new();
1617

1718
public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
1819
{
@@ -54,8 +55,11 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
5455
return SQSRequestHandler.HandleSQSRequest(instrumentedMethodCall, agent, transaction, request, isAsync, executionContext);
5556
}
5657

57-
if (_unsupportedRequestTypes.Add(requestType)) // log once per unsupported request type
58+
if (!_unsupportedRequestTypes.Contains(requestType)) // log once per unsupported request type
59+
{
5860
agent.Logger.Debug($"AwsSdkPipelineWrapper: Unsupported request type: {requestType}. Returning NoOp delegate.");
61+
_unsupportedRequestTypes.Add(requestType);
62+
}
5963

6064
return Delegates.NoOp;
6165
}

src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AwsSdk/SQSRequestHandler.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading.Tasks;
88
using NewRelic.Agent.Api;
99
using NewRelic.Agent.Extensions.AwsSdk;
10+
using NewRelic.Agent.Extensions.Collections;
1011
using NewRelic.Agent.Extensions.Providers.Wrapper;
1112
using NewRelic.Reflection;
1213

@@ -15,7 +16,7 @@ namespace NewRelic.Providers.Wrapper.AwsSdk
1516
internal static class SQSRequestHandler
1617
{
1718
private static readonly ConcurrentDictionary<Type, Func<object, object>> _getRequestResponseFromGeneric = new();
18-
private static readonly HashSet<string> _unsupportedSQSRequestTypes = [];
19+
private static readonly ConcurrentHashSet<string> _unsupportedSQSRequestTypes = [];
1920

2021
public static AfterWrappedMethodDelegate HandleSQSRequest(InstrumentedMethodCall instrumentedMethodCall, IAgent agent, ITransaction transaction, dynamic request, bool isAsync, dynamic executionContext)
2122
{
@@ -35,8 +36,11 @@ public static AfterWrappedMethodDelegate HandleSQSRequest(InstrumentedMethodCall
3536
action = MessageBrokerAction.Purge;
3637
break;
3738
default:
38-
if (_unsupportedSQSRequestTypes.Add(requestType)) // log once per unsupported request type
39+
if (!_unsupportedSQSRequestTypes.Contains(requestType)) // log once per unsupported request type
40+
{
3941
agent.Logger.Debug($"AwsSdkPipelineWrapper: SQS Request type {requestType} is not supported. Returning NoOp delegate.");
42+
_unsupportedSQSRequestTypes.Add(requestType);
43+
}
4044

4145
return Delegates.NoOp;
4246
}

0 commit comments

Comments
 (0)