-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,6 +411,7 @@ public async Task Invoke(IAddressable target, IInvokable invokable, Message mess | |
|
||
if (message.Direction != Message.Directions.OneWay) | ||
{ | ||
TransactionContext.Clear(); | ||
SafeSendExceptionResponse(message, exc1); | ||
} | ||
return; | ||
|
@@ -430,6 +431,7 @@ public async Task Invoke(IAddressable target, IInvokable invokable, Message mess | |
|
||
if (message.Direction != Message.Directions.OneWay) | ||
{ | ||
TransactionContext.Clear(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
||
|
@@ -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; | ||
|
@@ -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 | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.