GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Reset pooled session isolation level before reuse (fixes #96) by priyankatiwari08 · Pull Request #4330 · dotnet/SqlClient

Conversation

@priyankatiwari08

@priyankatiwari08 priyankatiwari08 commented Jun 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #96

Summary

SQL Server does not reset a session's transaction isolation level through sp_reset_connection, so a pooled connection can leak an elevated level to its next user.

This change adds the default-off AppContext switch Switch.Microsoft.Data.SqlClient.EnableTransactionIsolationLevelReset. When enabled, SqlClient tracks non-default transaction isolation levels and resets them to READ COMMITTED on pool checkout when no existing enlistment or active delegated transaction root remains.

The reset adds one round trip only when a changed connection is reused, using the caller's remaining Open timeout budget rather than the user command timeout. Known Azure Synapse dedicated SQL pool endpoints are excluded because they reject this statement; serverless endpoints remain eligible, including Private Link forms.

Tests

Covers SqlTransaction and TransactionScope, synchronous and asynchronous opens and queries, default-off compatibility behavior, same-scope reuse, detached delegated roots, reset timeout budgets through both pools, and Synapse endpoint classification.

  • Tests added or updated
  • Public API changes documented — no public API change
  • Verified against customer repro
  • No breaking changes introduced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rgroenewoudt and Timovzl reacted with thumbs up emoji dziegler-oc reacted with rocket emoji
All reactions
  • 👍 2 reactions
  • 🚀 1 reaction
Copilot AI lite review requested due to automatic review settings June 1, 2026 13:59
@priyankatiwari08
priyankatiwari08 requested a review from a team as a code owner June 1, 2026 13:59
@github-project-automation github-project-automation Bot added this to SqlClient Board Jun 1, 2026
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Jun 1, 2026
Copilot started reviewing on behalf of priyankatiwari08 June 1, 2026 14:00
View session
Copilot AI reviewed Jun 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@priyankatiwari08
Reset session isolation level on pool return (fixes dotnet#96)
9f67fb1
SqlTransaction and TransactionScope leave the underlying SQL Server session with the elevated isolation level after Commit/Rollback. sp_reset_connection does not reset it, so the next user of the pooled physical connection silently inherits it.

This change tracks when a non-default isolation level was set via the TM Begin path and, on pool return, issues a 'SET TRANSACTION ISOLATION LEVEL READ COMMITTED' batch right before sp_reset_connection (piggybacked on the same TDS header, no extra round trip). On failure the connection is doomed instead of returned to the pool.

A new AppContext switch 'Switch.Microsoft.Data.SqlClient.UseLegacyIsolationLevelBehavior' preserves previous behavior for callers that depend on it (default: false).

Adds IsolationLevelLeakTest under ManualTests covering the two repro scenarios plus a negative test for the kill switch.
@priyankatiwari08
priyankatiwari08 force-pushed the feature/sqltransaction-isolation-leak branch from 4e8ed47 to 9f67fb1 Compare June 1, 2026 14:19
@priyankatiwari08
priyankatiwari08 requested a review from Copilot June 1, 2026 14:20
Copilot started reviewing on behalf of priyankatiwari08 June 1, 2026 14:21
View session
@priyankatiwari08 priyankatiwari08 added this to the 7.0.2 milestone Jun 1, 2026
Copilot AI reviewed Jun 1, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/TransactionTest/IsolationLevelLeakTest.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/TransactionTest/IsolationLevelLeakTest.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/TransactionTest/IsolationLevelLeakTest.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

apoorvdeshmukh
apoorvdeshmukh requested changes Jun 1, 2026
View reviewed changes

@apoorvdeshmukh apoorvdeshmukh left a comment

Copy link
Copy Markdown
Contributor

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.

Can you look into this test failure?
Seems related to the changes

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-project-automation github-project-automation Bot moved this from To triage to Waiting for customer in SqlClient Board Jun 1, 2026
@apoorvdeshmukh apoorvdeshmukh self-assigned this Jun 1, 2026
@priyankatiwari08 priyankatiwari08 mentioned this pull request Jun 3, 2026
Re-issue session isolation level on TransactionScope re-enlistment #4335
Merged
4 tasks done
@priyankatiwari08
Address PR review: fix LegacySwitch test cached-switch flake
abc07ca
- IsolationLevelLeakTest: switch to LocalAppContextSwitchesHelper so the cached LocalAppContextSwitches value is forced, not just set via AppContext.SetSwitch (production code reads the cache after first use, which made the negative test order-dependent and caused the CI failure).

- Helper restores the previous value on dispose, so global state does not leak to other tests.

- TransactionScope test: set Enlist=true explicitly on the pooled connection string so the test does not depend on the user's local DataTestUtility.TCPConnectionString defaults.

- LocalAppContextSwitchesHelper: expose UseLegacyIsolationLevelBehavior get/set + capture/restore wired through the standard reflection helpers.
@priyankatiwari08 priyankatiwari08 moved this from Waiting for customer to In progress in SqlClient Board Jun 3, 2026
@priyankatiwari08
priyankatiwari08 requested a review from apoorvdeshmukh June 3, 2026 08:34
apoorvdeshmukh
apoorvdeshmukh previously requested changes Jun 3, 2026
View reviewed changes

@apoorvdeshmukh apoorvdeshmukh left a comment

Copy link
Copy Markdown
Contributor

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.

Can you look into this failure for LegacySwitch_PreservesOldLeakBehavior?
Tests are mostly failing with this one. You can put the PR into draft till this is addressed.
Is this happening only in CI or do you observe it locally under VS as well?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-project-automation github-project-automation Bot moved this from In progress to Waiting for customer in SqlClient Board Jun 3, 2026
@apoorvdeshmukh apoorvdeshmukh added the Author attention needed PRs that require author to respond or make updates to PR. label Jun 3, 2026
@priyankatiwari08
Gate LegacySwitch_PreservesOldLeakBehavior to non-Azure
dbefb9c
The leak only manifests on on-prem SQL Server: Azure SQL DB resets the session isolation level inside sp_reset_connection, so the legacy switch becomes a no-op there and the assertion (expects 'Serializable' to leak) fails on Azure CI legs.
Copilot AI review requested due to automatic review settings June 3, 2026 11:45
Copilot started reviewing on behalf of priyankatiwari08 June 3, 2026 11:45
View session
@priyankatiwari08
priyankatiwari08 marked this pull request as draft June 3, 2026 11:47
Copilot AI reviewed Jun 3, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/TransactionTest/IsolationLevelLeakTest.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

edwardneal
edwardneal reviewed Jun 3, 2026
View reviewed changes
Comment thread src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mdaigle mdaigle modified the milestones: 7.0.2, 7.1.0-preview2 Jun 9, 2026
This was referenced Nov 27, 2026
Bump Microsoft.AspNetCore.Authentication.JwtBearer and 17 others farooqngp/edu-eco#44
Open
deps: Bump the spark-example-nuget-major group with 1 update incendilabs/spark-facade-example#13
Open
Bump Microsoft.Data.SqlClient and System.Text.Json devopsabcs-engineering/gh-advsec-devsecops#83
Open
Bump Microsoft.Data.SqlClient from 7.1.2 to 8.0.0 erikdarlingdata/PerformanceMonitor#9869
Merged
Bump Microsoft.Data.SqlClient.Extensions.Azure from 7.1.2 to 8.0.0 erikdarlingdata/PerformanceMonitor#9870
Closed
Bump Microsoft.Bcl.Cryptography and 8 others mishka1c/mRemoteNX#14
Closed
Bump Microsoft.Data.SqlClient from 7.1.2 to 8.0.0 Qowaiv/Qowaiv#746
Open
Bump Microsoft.Data.SqlClient from 7.1.2 to 8.0.0 futugyou/DDDExample#397
Merged
Bump the microsoft group with 12 updates ericksonlopezf/dotnet-sql-builder#24
Open
Bump the microsoft group with 12 updates protobuf-net/protobuf-net#1399
Open
Bump the all-dependencies group with 4 updates sebastienros/yessql#767
Open
Bump the dotnet group with 12 updates newbothi/reservamed#50
Open
Bump coverlet.collector and 10 others newbothi/reservamed#51
Open
Bump Microsoft.Data.SqlClient from 7.1.1 to 8.0.0 olesme/ohirok.reqnroll#5
Closed
Bump Microsoft.Data.SqlClient from 7.1.2 to 8.0.0 giis-uniovi/tdrules#797
Open
Bump Microsoft.Data.SqlClient and System.Security.Cryptography.Pkcs Arc4u-org/Arc4u#297
Open
Bump Microsoft.Data.SqlClient from 7.1.2 to 8.0.0 kris701/DatabaseSharp#12
Closed
Bump Aspire.Hosting.Azure.ServiceBus and 21 others softvasco/ledger-core#134
Open
Bump FsCheck.Xunit.v3 and 17 others softvasco/ledger-core#135
Open
chore: Bump Microsoft.Data.SqlClient and System.Security.Cryptography.Pkcs Lethabarb/grow2notes#262
Open
Bump Microsoft.Data.SqlClient from 6.1.4 to 8.0.0 rpgrca/EjerciciosEnNET#745
Open
Bump Microsoft.Data.SqlClient from 7.1.2 to 8.0.0 emimaldo/agentic-workflow-poc#13
Open
Bump Microsoft.Data.SqlClient and Microsoft.EntityFrameworkCore.SqlServer JASSBR/comptoir#27
Open
Bump Microsoft.Data.SqlClient and System.Security.Cryptography.Pkcs moberghr/beacon#288
Open
Bump the microsoft group with 17 updates ibrahimsamak/Azure-Kubernetes-AKS-ACR#60
Open
Bump the database-providers group with 2 updates HilthonTT/MicroORM#9
Merged
Bump Microsoft.Data.SqlClient from 7.1.2 to 8.0.0 XLibur/XLibur#1042
Open
Bump Microsoft.AspNetCore.Authentication.JwtBearer and 7 others ahmedgndy/AlMotaheda_ERP#21
Open
Bump the nuget group with 16 updates Keboo/SimplyBudget#336
Open
Bump Microsoft.Data.SqlClient and System.Security.Cryptography.Pkcs Ashish-ingh123/billingrecon#15
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mdaigle mdaigle mdaigle approved these changes
Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@paulmedynski paulmedynski paulmedynski approved these changes
@benrr101 benrr101 Awaiting requested review from benrr101
@apoorvdeshmukh apoorvdeshmukh Awaiting requested review from apoorvdeshmukh
+1 more reviewer
@edwardneal edwardneal edwardneal left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@benrr101 benrr101

@mdaigle mdaigle

@paulmedynski paulmedynski

Labels

None yet

Projects

SqlClient Board
Status: Done

Milestone

8.0.0-preview1

Development

Successfully merging this pull request may close these issues.

SqlTransaction and TransactionScope leak isolation level

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@priyankatiwari08 @benrr101 @mdaigle @apoorvdeshmukh @paulmedynski @edwardneal @cheenamalhotra
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.