Stage 3: reset acking + isolation carrier (ADO #47339) - #301
Closed
Saurabh Singh (saurabh500) wants to merge 1 commit into
Closed
Conversation
Drive the RESETCONNECTION round trip eagerly inside SQLSetConnectAttr(SQL_ATTR_RESET_CONNECTION) so the reset is processed and acknowledged before pool checkout returns, rather than riding a later request that may short-circuit. A failed reset poisons the client and surfaces 08S01 so mssql-python discards the connection. Add TdsClient::reset_connection() (arms the bit and forces the ack round trip) and mark_connection_dead(); wire the ODBC handler to them, map failures to 08S01, and document the D9 raw-T-SQL isolation caveat at the same-value short-circuit. Cover the eager ack, poison, reset+isolation re-apply, and full checkout-cycle lifecycle with unit/mock tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63e24621-7665-4572-a5b8-e5dfa55060a0
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Stage 3 of the mssql-odbc connection pooling effort (ADO User Story #47317, Task
[AB#47339](https://sqlclientdrivers.visualstudio.com/b95cf060-8083-439d-8ef1-405d5bf219d8/_workitems/edit/47339)). Makes the connection reset self-acking at pool checkout so a borrower never inherits a session whose reset has not yet been processed, and confirms the isolation/autocommit checkout lifecycle carries and survives the reset.Stacked on Stage 2 PR #296 (→ #294 → #293). Base branch:
saurabh500-stage-2-odbc-pooling-primitives, notmain.A2 — reset is self-acking (
mssql-tds)TdsClient::reset_connection(): arms the full RESETCONNECTION bit and drives a minimalSELECT 1round trip so the server processes the reset and returns itsResetConnectionENVCHANGE within the call. The ack flows through Stage 1'son_reset_connection_ack(), clearing session-bound caches before checkout. A failed round trip returns an error so the caller can discard the connection.prepare_reset_connection(bool)is unchanged (the deferred-piggyback path);reset_connection()is the eager variant.TdsClient::mark_connection_dead()lets the ODBC layer deterministically poison a client whose reset failed.B4 — wire eager reset + isolation carrier (
mssql-odbc)SQLSetConnectAttr(SQL_ATTR_RESET_CONNECTION)now callsreset_connection()after arming, so the reset is processed+acked before the set-attr returns. The DBC mutex is never held across the round-trip I/O (claim → drop lock → I/O → restore). On failure it poisons the client and surfaces08S01so mssql-python discards it at checkout.SQL_ATTR_TXN_ISOLATIONhandler still emits a realSET TRANSACTION ISOLATION LEVELbatch; because the reset now acks eagerly, a later short-circuited isolation SET can't leave the reset unacknowledged. Test covers a borrower raising isolation to SERIALIZABLE, resetting, then re-applying READ COMMITTED at checkout.B5 — autocommit / EndTran lifecycle confirmation
setautocommit(False)(begin-txn) → check-in → next acquire (reset) reuses the same physical connection and leaves it reusable. No autocommit/EndTran plumbing rebuilt.Tests
mssql-tdsandmssql-odbc: eager-ack round trip, failure poison →08S01, reset+isolation re-apply, and the full checkout lifecycle. Extendedtest_client_supportwith aResetConnectionENVCHANGE token helper andmark_known_deadsupport on the replay transport.Validation
cargo bfmt✅ (workspace +mssql-py-core)cargo bclippy✅ (warnings-as-errors, clean)mssql-tds/mssql-odbclib unit tests ✅ — the only failures are the pre-existing cert/TLS-fixture tests on the base, unrelated to this change.References
[AB#47339](https://sqlclientdrivers.visualstudio.com/b95cf060-8083-439d-8ef1-405d5bf219d8/_workitems/edit/47339).