Stage 1: mssql-tds reset correctness (ADO #47337) - #294
Draft
Saurabh Singh (saurabh500) wants to merge 1 commit into
Draft
Conversation
Route every ResetConnection ENVCHANGE through a single on_reset_connection_ack that resets session state, clears session-bound prepared caches (shared with the reconnect path), and restores the negotiated database/language/collation to their login values. Add TdsTransport::mark_known_dead and flag the transport dead when a server error token has severity/class >= 20, so a pool checkout discards a fatally errored connection even on a still-open socket. Add unit tests for the reset transition and the fatal-error path, plus a live test proving a prepared handle is invalidated across a reset. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 63e24621-7665-4572-a5b8-e5dfa55060a0
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 1 of the mssql-odbc connection pooling effort (ADO User Story #47317). This is the bottom implementation layer, scoped to
mssql-tdsonly — it makes a physical connection reset actually clean the session-bound client state so a pool can safely hand a reused connection to the next borrower.mssql-odbcwiring comes in later stages.Implements Workstream A (A1, A3) and discovery D3 from
docs/odbc-connection-pooling-plan.md.A1 — Centralize the ResetConnection ENVCHANGE acknowledgement
Previously the ResetConnection ENVCHANGE was handled in 5 token-draining spots that each only called
session_state_table.reset(), leaving session-bound client caches stale after a real server reset.TdsClient::on_reset_connection_ack()performs the full post-reset transition: resets the session-state table, clearsprepared_handles/prepared_param_encryption/pending_capture/pending_prepared_param_encryption, and restores the negotiated DATABASE / LANGUAGE / COLLATION back to their login values (so a borrower'sUSE otherdb/SET LANGUAGEdoesn't persist across a reset).clear_session_bound_caches()helper reused by the reconnect path.capture_change_propertyordering is preserved (login-default restore moved out ofexecution_contextinto the single owner to avoid duplication).fODBCLOGIN7 bit thatsp_reset_connectionrestores. NoBuildServerSideConnectOptionsequivalent added.D3 — Mark the transport dead on fatal server error tokens
known_deadwas only set on socket write/read failure, EOF, or explicit close; a class ≥ 20 fatal error on a still-open socket leftis_connection_dead()reporting alive.TdsTransport::mark_known_dead()(default no-op; overridden byNetworkTransport).record_error_token) now marks the transport known-dead whenseverity >= 20, so a later pool checkout discards it.A3 — Tests
tests/test_reset_connection.rsproving a prepared handle is invalidated across a reset (gated on a live SQL Server via.env, like the sibling reset tests).Validation
cargo bfmt✅cargo bclippy(warnings-as-errors) ✅cargo nextest— new/related tests pass. Pre-existing certificate/TLS-validation test failures are unrelated to this change (they fail on the base branch too, expired cert fixtures).Notes
saurabh500-odbc-connection-pooling-plan); this PR targets that branch, notmain.[AB#47337](https://sqlclientdrivers.visualstudio.com/b95cf060-8083-439d-8ef1-405d5bf219d8/_workitems/edit/47337).