-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[rc2] Fix concurrency issue in RelationalConnection ambient transaction handling #36665
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
Conversation
AndriySvyryd
left a comment
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.
@copilot Rewrite the PR summary using this template:
Fixes #{number}
**Description**
{Issue description}
**Customer impact**
{How does the reported issue affects customer's app? Are there workarounds?}
**How found**
{Was it customer reported or found during verification? How many customers are affected?}
**Regression**
{Is it a regression from a released version? Which one?}
**Testing**
{How the changes were tested}
**Risk**
{Low/Medium/High, argument why}
... Here's the updated PR description using the template: Fixes #35856 Description Customer impact How found Regression Testing
Risk |
artl93
left a comment
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.
Customer reported regression. Customer reports it happening "randomly," which makes sense for this bug.
This is gonna be hard to know if we fixed it or if we might have another lingering regression behind this one.
From a risk perspective, this seems like a low level concurrency fix that if it weren't customer reported, I don't think we would want to take this risk right now. Is there anyway we can validate that this directly fixes the customer report?
1bb6bb8 to
c211044
Compare
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…ck-box testing Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
c211044 to
044f425
Compare
I wasn't able to repro it with MSDTC as in the report. The test does hit it, but only when run in the debugger. However, I found that the original fix introduced a deadlock since the lock is around an event handler being unsubscribed and that waits for the handler to finish executing, but it was waiting on the same lock. So, seeing that this only is a problem that could happen when the connection is being disposed, I implemented a less risky fix without synchronization that just avoids throwing an exception in this case. |
artl93
left a comment
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.
Approved, RC2. I appreciate that we can get this under the debugger and that we’re making a more narrow fix.
Fixes #35856
Description
There was a race condition between
ClearTransactionsandHandleTransactionCompletedmethods inRelationalConnectionthat could cause exceptions in distributed transaction scenarios accessing_ambientTransactionsfrom different threads.Customer impact
The issue affects applications using distributed transactions with MSDTC. Customers experience random application failures with no clear workaround other than avoiding distributed transactions.
How found
Customer reported on EF8.
Regression
Yes, from EF Core 3.1. Introduced in #20012
Testing
Test added
Risk
Low. Changes are focused on improving thread safety of existing ambient transaction functionality. The synchronization is only applied when ambient transactions are used, minimizing performance impact on regular database operations.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.