-
Notifications
You must be signed in to change notification settings - Fork 317
[6.0] Fix connection pool concurrency issue (#3632) #3654
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
[6.0] Fix connection pool concurrency issue (#3632) #3654
Conversation
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 introducing a new SemaphoreHolder
class that properly manages semaphore acquisition and release using the disposable pattern. The fix ensures that semaphores are automatically released even when exceptions occur, preventing potential deadlocks in connection pool operations.
Key Changes
- Introduces a new
SemaphoreHolder
class that implementsIDisposable
for automatic semaphore cleanup - Refactors semaphore usage in
TryGetConnection
andPoolCreateRequest
methods to use the new pattern - Adds comprehensive connection pool stress tests to validate concurrent behavior
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
ConnectionPoolStressTest.cs | New test file with comprehensive stress testing for connection pool concurrency scenarios |
Microsoft.Data.SqlClient.ManualTesting.Tests.csproj | Includes the new stress test file in the test project |
DbConnectionPool.cs | Implements the SemaphoreHolder class and refactors semaphore management to prevent concurrency issues |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs
Outdated
Show resolved
Hide resolved
...icrosoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolStressTest.cs
Show resolved
Hide resolved
...crosoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj
Outdated
Show resolved
Hide resolved
…SqlClient.ManualTesting.Tests.csproj
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release/6.0 #3654 +/- ##
===============================================
+ Coverage 72.73% 75.82% +3.08%
===============================================
Files 285 244 -41
Lines 59162 40211 -18951
===============================================
- Hits 43034 30489 -12545
+ Misses 16128 9722 -6406
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:
|
src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs
Show resolved
Hide resolved
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.
The test code is mostly unused, please either remove it or operationalize it.
Take a look at the placement of the PreapreConstrainedRegions call in theDbConnectionPool class.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs
Outdated
Show resolved
Hide resolved
...icrosoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolStressTest.cs
Show resolved
Hide resolved
...icrosoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolStressTest.cs
Show resolved
Hide resolved
...icrosoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolStressTest.cs
Show resolved
Hide resolved
...icrosoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolStressTest.cs
Show resolved
Hide resolved
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.
These tests need a lot of work before I'd approve of them normally. But I'm in a bind because this work has already been accepted on main, and the fix is important enough. I'd prefer it if you didn't submit this test file as part of this PR and back out the file in main. But considering you want it released asap since it's not really harming anything to add more incomplete code to the mountain of incomplete code in our test folders.
Ports #3632 to release/6.0