-
Notifications
You must be signed in to change notification settings - Fork 314
Fix | Improve error handling when creating performance counters #3623
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
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
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.
Change looks good. Is there a way to alter one or more of the existing integration tests to remove the counter support before running these tests? Would that have caught the regression?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3623 +/- ##
==========================================
- Coverage 67.94% 58.45% -9.50%
==========================================
Files 276 270 -6
Lines 61641 61324 -317
==========================================
- Hits 41885 35847 -6038
- Misses 19756 25477 +5721
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:
|
I gave some thought to writing a test, but I think it'd be pretty fragile. In theory we could have a test which manually runs |
Fair enough, if you tested manually then I'm happy. I did happen to just discover that all Manual Tests are being run serially, so I guess such a test would work today without perturbing other tests :) I agree that it's probably not worth it currently though. |
Description
This may need to be backported to 6.1.
#3251 refactored DbConnectionPoolCounters (a netfx-specific class) into a platform-independent SqlClientMetrics class. While the performance counter creation logic remained the same, I introduced a bug in the exception handling.
SqlClient/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolCounters.netfx.cs
Lines 104 to 122 in c12134a
In the original logic, if an InvalidOperationException was thrown then the exception handler ran before assigning a value to the class' performance counter. In the refactored logic, the counter was returned anyway.
The net effect of this is that if a performance counter failed to initialise (such as if the ".NET Data Provider for SqlServer" provider wasn't present) then it'd be returned in an uninitialised state. The next attempt to increment the counter would try to initialise it again, failing again.
Issues
Fixes #3595.
Testing
I don't think there's a way to add a non-intrusive automatic test, but a manual test works properly.
To break this, I ran:
unlodctr ".NET Data Provider for SqlServer"
main currently fails with an InvalidOperationException, and it's resolved by running:
lodctr "C:\Windows\INF\.NET Data Provider for SqlServer\_dataperfcounters_shared12_neutral.ini"
After this fix, the performance counters now silently fail (and tracing records the error while initializing.)