-
Notifications
You must be signed in to change notification settings - Fork 317
Fix connection pool concurrency issue #3632
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
…le semaphore handles, instead of only creation handle during pool create request.
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.
Pull Request Overview
This PR fixes a concurrency issue in the connection pool by changing how semaphore handles are waited on during pool creation requests. Instead of waiting on multiple semaphore handles simultaneously, it now waits only on the creation handle to prevent potential race conditions.
- Replaces
WaitHandle.WaitAny()
with directWaitOne()
on the creation semaphore - Simplifies the wait result handling logic by removing the intermediate wait result case
- Removes unnecessary error tracing for non-timeout wait failures
...oft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/WaitHandleDbConnectionPool.cs
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3632 +/- ##
===========================================
+ Coverage 66.13% 90.82% +24.69%
===========================================
Files 276 6 -270
Lines 60765 316 -60449
===========================================
- Hits 40184 287 -39897
+ Misses 20581 29 -20552
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Asking to simplify/clarify the semaphore block.
Also, is there a way to test this?
...oft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/WaitHandleDbConnectionPool.cs
Outdated
Show resolved
Hide resolved
This might also need to be backported to v5.1. #2390 ported the change from netcore, which has exactly the same behaviour: SqlClient/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs Line 1482 in ee2d196
v6.0 is the first point that it impacted netfx, but this has been the netcore behaviour from the outset of the driver (even when going back to the PR which added System.Data.SqlClient to its first version of netcore.) |
I've verified this directly as well as in the test suite, this doesn't seem to cause any concerns with the repro I have, also added as a test case in the PR. The same test case fails with NetFx (without fix), but passes in NetCore without any changes. I'm going to give that a pass unless there are any reported concerns. It maybe possible that there's a different difference between NetFx and NetCore source that is part of the problem. But I'll leave that until code merge happens for all the layers. The test case will fail if after merge there is inconsistency in functionality and we'll know! |
Fixes connection pool concurrency issue caused due to waiting on multiple semaphore handles, instead of only creation handle during pool create request.
Issue was first introduced in PR #2390 (https://github.com/dotnet/SqlClient/pull/2390/files#diff-d7c1dbddf2a7e205d7a85cbafbef036899799672dd5d1c486a64a05979e92230R1627) and has affected MDS v6 onwards.
Needs to be backported to v6.0 and v6.1 branches as well.