Skip to content

Commit

Permalink
fix: Fix potential race condition in AWS SDK, AWS Bedrock, and Elasti…
Browse files Browse the repository at this point in the history
…search that could lead to an orphaned Transaction. (#2842)
  • Loading branch information
jaffinito authored Oct 21, 2024
1 parent ba9ee7b commit 3afa15f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ ISegment StartMessageBrokerSegment(MethodCall methodCall, MessageBrokerDestinati
/// <summary>
/// Detatches the transaction from each non-async active context storage. This is necessary when async tracking needs to continue but
/// the primary context(s) the transaction may be stored can continue to persist, such as thread static or thread local storgage.
/// <para>
/// <b>Warning:</b> This method should only be called at the start of the transaction, before any other segments are created.
/// If called partway through the transaction, this can result in "Transaction was garbage collected without ever ending" errors.
/// </para>
/// </summary>
void DetachFromPrimary();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
if (isAsync)
{
transaction.AttachToAsync();
transaction.DetachFromPrimary(); //Remove from thread-local type storage
}

// Get the IRequestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
if (instrumentedMethodCall.IsAsync)
{
transaction.AttachToAsync();
transaction.DetachFromPrimary(); //Remove from thread-local type storage
}

dynamic invokeModelRequest = instrumentedMethodCall.MethodCall.MethodArguments[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
if (isAsync)
{
transaction.AttachToAsync();
transaction.DetachFromPrimary(); //Remove from thread-local type storage

var parameterTypeNamesList = instrumentedMethodCall.InstrumentedMethodInfo.Method.ParameterTypeNames.Split(',');
if (parameterTypeNamesList[4] == "Elasticsearch.Net.IRequestParameters")
{
Expand Down

0 comments on commit 3afa15f

Please sign in to comment.