Skip to content

Commit 3afa15f

Browse files
authored
fix: Fix potential race condition in AWS SDK, AWS Bedrock, and Elastisearch that could lead to an orphaned Transaction. (#2842)
1 parent ba9ee7b commit 3afa15f

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Api/ITransaction.cs

+4
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ ISegment StartMessageBrokerSegment(MethodCall methodCall, MessageBrokerDestinati
165165
/// <summary>
166166
/// Detatches the transaction from each non-async active context storage. This is necessary when async tracking needs to continue but
167167
/// the primary context(s) the transaction may be stored can continue to persist, such as thread static or thread local storgage.
168+
/// <para>
169+
/// <b>Warning:</b> This method should only be called at the start of the transaction, before any other segments are created.
170+
/// If called partway through the transaction, this can result in "Transaction was garbage collected without ever ending" errors.
171+
/// </para>
168172
/// </summary>
169173
void DetachFromPrimary();
170174

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

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
3030
if (isAsync)
3131
{
3232
transaction.AttachToAsync();
33-
transaction.DetachFromPrimary(); //Remove from thread-local type storage
3433
}
3534

3635
// Get the IRequestContext

src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/Bedrock/InvokeModelAsyncWrapper.cs

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
4040
if (instrumentedMethodCall.IsAsync)
4141
{
4242
transaction.AttachToAsync();
43-
transaction.DetachFromPrimary(); //Remove from thread-local type storage
4443
}
4544

4645
dynamic invokeModelRequest = instrumentedMethodCall.MethodCall.MethodArguments[0];

src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/Elasticsearch/RequestWrapper.cs

-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
4545
if (isAsync)
4646
{
4747
transaction.AttachToAsync();
48-
transaction.DetachFromPrimary(); //Remove from thread-local type storage
49-
5048
var parameterTypeNamesList = instrumentedMethodCall.InstrumentedMethodInfo.Method.ParameterTypeNames.Split(',');
5149
if (parameterTypeNamesList[4] == "Elasticsearch.Net.IRequestParameters")
5250
{

0 commit comments

Comments
 (0)