Skip to content

Conversation

@edwardneal
Copy link
Contributor

Description

This PR fixes a minor correctness issue and might also contribute to #1687 - this field was one of several lingering on the heap when trying to unload a collectible AssemblyLoadContext.

The managed SNI's SniLoadHandle currently has a per-thread LastError property which references a ThreadLocal<SniError>. ThreadLocal is disposable, but we have no clear opportunity to dispose of it when the AssemblyLoadContext is unloaded.

The entire class is a singleton which only exposes a single meaningful property, LastError. I've converted SniLoadHandle into a static class, then replaced the ThreadLocal with a simpler [ThreadStatic] variable.

Issues

Related to #1687. It doesn't fix the issue, but it's one of the two fixes which are easiest to pick out from a broader set of changes.

Testing

Automated tests continue to pass.

@edwardneal edwardneal requested a review from a team as a code owner November 14, 2025 16:19
@mdaigle
Copy link
Contributor

mdaigle commented Nov 14, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@paulmedynski paulmedynski self-assigned this Nov 17, 2025
@paulmedynski
Copy link
Contributor

paulmedynski commented Nov 17, 2025

@edwardneal This will need a rebase/merge from main to pickup the new PR pipeline configs.

@edwardneal
Copy link
Contributor Author

Thanks @paulmedynski I've just merged main.

@paulmedynski
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

❌ Patch coverage is 51.72414% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.95%. Comparing base (37dde3f) to head (4d787cb).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...ta/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs 0.00% 6 Missing ⚠️
...soft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs 28.57% 5 Missing ⚠️
...soft/Data/SqlClient/ManagedSni/SniError.netcore.cs 0.00% 1 Missing ⚠️
.../SqlClient/ManagedSni/SniMarsConnection.netcore.cs 0.00% 1 Missing ⚠️
...oft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs 66.66% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (37dde3f) and HEAD (4d787cb). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (37dde3f) HEAD (4d787cb)
addons 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3768      +/-   ##
==========================================
- Coverage   76.59%   69.95%   -6.65%     
==========================================
  Files         274      268       -6     
  Lines       43395    43075     -320     
==========================================
- Hits        33240    30134    -3106     
- Misses      10155    12941    +2786     
Flag Coverage Δ
addons ?
netcore 69.87% <51.72%> (-6.79%) ⬇️
netfx 69.46% <ø> (-6.68%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paulmedynski paulmedynski merged commit 995df25 into dotnet:main Nov 19, 2025
493 checks passed
@edwardneal edwardneal deleted the feat/assemblyloadcontext-1687/sniloadhandle branch November 19, 2025 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants