Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear transaction context in top level transaction #3730

Merged
merged 2 commits into from
Dec 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions src/Orleans.Runtime/Core/InsideRuntimeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ public async Task Invoke(IAddressable target, IInvokable invokable, Message mess

if (message.Direction != Message.Directions.OneWay)
{
TransactionContext.Clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be cleared regardless of the direction?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, but it probably doesn't matter. What's critical here is whether the context is still set when building the response message. For calls that created the context, or when exceptions are thrown, the transaction context should be cleared prior to building a response.

SafeSendExceptionResponse(message, exc1);
}
return;
Expand All @@ -430,6 +431,7 @@ public async Task Invoke(IAddressable target, IInvokable invokable, Message mess

if (message.Direction != Message.Directions.OneWay)
{
TransactionContext.Clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here... at first thought at least seems that it should clear before returning, regardless of direction... I might be wrong, as I didn't follow it very thoroughly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, nevermind, I see now that this whole block is wrapped with a try/finally where you clear in the finally statement


In reply to: 154475381 [](ancestors = 154475381)

SafeSendExceptionResponse(message, abortException);
}

Expand All @@ -440,6 +442,7 @@ public async Task Invoke(IAddressable target, IInvokable invokable, Message mess
{
// This request started the transaction, so we try to commit before returning.
await this.transactionAgent.Value.Commit(transactionInfo);
TransactionContext.Clear();
}

if (message.Direction == Message.Directions.OneWay) return;
Expand All @@ -449,20 +452,27 @@ public async Task Invoke(IAddressable target, IInvokable invokable, Message mess
catch (Exception exc2)
{
logger.Warn(ErrorCode.Runtime_Error_100329, "Exception during Invoke of message: " + message, exc2);
if (message.Direction != Message.Directions.OneWay)
SafeSendExceptionResponse(message, exc2);

if (exc2 is OrleansTransactionInDoubtException)
try
{
this.logger.LogError(exc2, "Transaction failed due to in doubt transaction");
if (exc2 is OrleansTransactionInDoubtException)
{
this.logger.LogError(exc2, "Transaction failed due to in doubt transaction");
}
else if (TransactionContext.GetTransactionInfo() != null)
{
// Must abort the transaction on exceptions
TransactionContext.GetTransactionInfo().IsAborted = true;
var abortException = (exc2 as OrleansTransactionAbortedException) ??
new OrleansTransactionAbortedException(TransactionContext.GetTransactionInfo().TransactionId, exc2);
this.transactionAgent.Value.Abort(TransactionContext.GetTransactionInfo(), abortException);
}
}
else if (TransactionContext.GetTransactionInfo() != null)
finally
{
// Must abort the transaction on exceptions
TransactionContext.GetTransactionInfo().IsAborted = true;
var abortException = (exc2 as OrleansTransactionAbortedException) ??
new OrleansTransactionAbortedException(TransactionContext.GetTransactionInfo().TransactionId, exc2);
this.transactionAgent.Value.Abort(TransactionContext.GetTransactionInfo(), abortException);
TransactionContext.Clear();
if (message.Direction != Message.Directions.OneWay)
SafeSendExceptionResponse(message, exc2);
}
}
finally
Expand Down