Skip to content

FIX: Respect explicit connection timeout during pooled checkout - #897

Merged
Jahnvi Thakkar (jahnvi480) merged 2 commits into
mainfrom
jahnvi/pooled-checkout-timeout-bef
Nov 13, 2026
Merged

Jahnvi Thakkar (jahnvi480) merged 2 commits into
mainfrom
jahnvi/pooled-checkout-timeout-bef

Conversation

@jahnvi480

@jahnvi480 Jahnvi Thakkar (jahnvi480) commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Work Item / Issue Reference

AB#50287

GitHub Issue: #893


Summary

Respect an explicit positive SQL_ATTR_CONNECTION_TIMEOUT during pooled checkout by using the smaller of the existing connection timeout and the login-derived validation timeout. Preserve the finite fallback for zero/unspecified timeouts and restore the original connection timeout after successful checkout.

Add native timeout-selection/restoration tests and socket-proxy regression cases for both autocommit modes. Document timeout precedence and driver retry latency.

Validation: rebuilt the Windows extension; live SQL Server instrumentation changed the observed validation timeout from 15 to 1 second while preserving physical connection reuse and restoring the original timeout. Native suite: 87 passed. Connection/exception/pooling suites: 314 passed, 33 skipped. Pinned Black check passed. Full-suite execution and failed-test rerun leave two environment-dependent failures: passwordless-auth logging expectation and Windows long-path handling. Packet-drop timing remains unverified because the available SQL Server supports named pipes, not TCP.

Use the shorter positive connection timeout for pooled validation and retain timeout restoration. Add regression coverage and document timeout precedence.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 07:22
@github-actions github-actions Bot added the pr-size: small Minimal code update label Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

PR Performance Report

✅ No regression detected

No consistent slowdowns detected across all 2 environments.

0 IMPROVEMENTS 0 SLOWDOWNS 2/2 ENVIRONMENTS

Coverage: 2 of 2 environments completed. Advisory result; does not block merging.

Performance diagnostics

Phase times are inclusive diagnostics and must not be added together. They identify where measured time changed, not why it changed.

No affected phases or call-count changes were recorded.

All database tasks and timings

Unix / SQL Server 2022

Database task Before After Paired change Result
Connection opening 10.612 ms 9.992 ms -5.6% no signal
SELECT queries 1.007 ms 0.994 ms -0.3% no signal
Row insertion 30.363 ms 30.955 ms +0.7% no signal
Executemany inserts 157.076 ms 156.579 ms -0.6% no signal
Fetch-all queries 117.429 ms 117.118 ms -0.3% no signal
Row-by-row fetching 4.854 ms 4.907 ms -0.1% no signal
Batched row fetching 114.957 ms 114.116 ms +0.7% no signal
Transaction commit and rollback 104.587 ms 104.304 ms -0.4% no signal
Arrow row fetching 88.155 ms 87.217 ms -1.3% no signal
100,000-row insertion 339.213 ms 351.601 ms +2.1% no signal
Row fetching in batches of 100 118.644 ms 122.355 ms +4.1% no signal
Row fetching in batches of 10,000 141.807 ms 125.305 ms -10.9% no signal
Repeated positional queries 31.788 ms 31.339 ms -1.7% no signal
Repeated named-parameter queries 31.981 ms 31.817 ms +0.0% no signal
Legacy 100,000-row insertion 261.004 ms 257.966 ms -0.3% no signal
Insertion with explicit input sizes 382.762 ms 391.922 ms +2.4% no signal
Joined aggregation queries 178.568 ms 179.848 ms +1.0% no signal
Large joined-result fetching 190.293 ms 192.279 ms +0.1% no signal
1.2-million-row fetching 3449.543 ms 3443.523 ms -0.2% no signal
Common table expression queries 5.329 ms 5.291 ms -1.6% no signal
256 KiB VARCHAR(MAX) / fetchall() 1.542 ms 1.586 ms +4.1% no signal
10,000 scalar values / fetchval() (debug disabled) 16.816 ms 16.490 ms -2.4% no signal
10,000 output-converted rows / fetchall() 19.076 ms 19.757 ms +4.5% no signal
10,000 output-converted rows / fetchmany(1000) 23.359 ms 23.825 ms +2.4% no signal
10,000 rows x 32 columns / dict(row._mapping) (warm) 31.655 ms 30.889 ms -0.9% no signal

Unix / SQL Server 2025

Database task Before After Paired change Result
Connection opening 81.066 ms 81.162 ms +0.4% no signal
SELECT queries 0.992 ms 0.979 ms -1.6% no signal
Row insertion 30.432 ms 30.149 ms -1.7% no signal
Executemany inserts 151.448 ms 150.073 ms -1.6% no signal
Fetch-all queries 118.491 ms 120.059 ms +1.1% no signal
Row-by-row fetching 4.862 ms 4.845 ms -0.2% no signal
Batched row fetching 115.386 ms 116.977 ms +2.0% no signal
Transaction commit and rollback 105.644 ms 104.368 ms -1.0% no signal
Arrow row fetching 87.553 ms 89.410 ms +2.1% no signal
100,000-row insertion 346.200 ms 343.350 ms -0.9% no signal
Row fetching in batches of 100 120.264 ms 122.188 ms +1.7% no signal
Row fetching in batches of 10,000 120.972 ms 138.315 ms +14.3% no signal
Repeated positional queries 31.753 ms 31.107 ms -4.2% no signal
Repeated named-parameter queries 31.701 ms 31.874 ms +0.7% no signal
Legacy 100,000-row insertion 266.047 ms 252.783 ms -0.3% no signal
Insertion with explicit input sizes 401.483 ms 380.766 ms -0.9% no signal
Joined aggregation queries 164.676 ms 164.107 ms -1.0% no signal
Large joined-result fetching 185.410 ms 187.501 ms +1.6% no signal
1.2-million-row fetching 3474.862 ms 3480.381 ms -0.0% no signal
Common table expression queries 5.194 ms 5.146 ms +1.0% no signal
256 KiB VARCHAR(MAX) / fetchall() 1.452 ms 1.958 ms -0.9% no signal
10,000 scalar values / fetchval() (debug disabled) 16.773 ms 16.753 ms -0.5% no signal
10,000 output-converted rows / fetchall() 19.995 ms 19.615 ms +2.0% no signal
10,000 output-converted rows / fetchmany(1000) 23.745 ms 23.795 ms -0.2% no signal
10,000 rows x 32 columns / dict(row._mapping) (warm) 31.563 ms 32.098 ms +1.7% no signal
Build and measurement details

ADO build 191839

PR head: 949572c4012f5b4adc8e6a2c96c8ba370906de66
Base: 0401492f34457b71ac1cd64a05c1d032d5863285
Measured merge: 842bc82cce6d5493545216761db9833ea63ecca1

  • Unix / SQL Server 2022: Python 3.12.3, x86_64, SQL 16.0.4325.4; 5 paired comparisons and 1 warmup.
  • Unix / SQL Server 2025: Python 3.12.3, x86_64, SQL 17.0.5065.9; 5 paired comparisons and 1 warmup.

A consistent change requires more than 20% median paired movement, at least 1 ms between the median runtimes, and at least 80% of pairs exceeding the relative threshold in the same direction. A slowdown without enough pair agreement is reported as inconsistent.

The displayed change is the median of paired before-and-after ratios. It is not recalculated from the two displayed median runtimes.

Both revisions use profiling-enabled builds on the same agent and database, with alternating order and discarded warmups. Results are diagnostic and do not represent production-wheel latency.

Raw samples and logs are attached to the ADO run as profiler-* artifacts.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Stalled-TCP checkout latency remains unverified because reported testing used only named pipes; human confirmation on a live TCP endpoint in both autocommit modes is needed to establish driver retry latency.

No open issues 🎉

What changed in this PR

Addresses #893 in the native connection pool by honoring a pooled connection’s shorter positive SQL_ATTR_CONNECTION_TIMEOUT during checkout validation, without requiring a shorter login timeout.

Changes:

  • Selects the smaller positive connection and login-derived timeouts while preserving the finite fallback and existing timeout restoration.
  • Adds native selection/restoration tests and stalled-socket regression cases for both autocommit modes.
  • Documents timeout precedence and why driver retries can extend elapsed checkout time.
File Description
tests/​test_009_pooling.py Adds explicit connection-timeout proxy cases for both autocommit modes and adjusts fallback detection.
tests/​native/​pool_sanitation.cpp Tracks timeout state and verifies selection, restoration, and physical connection reuse.
README.md Explains connection-timeout precedence and retry-related latency.
mssql_python/​pybind/​connection/​connection.cpp Caps checkout validation at the existing positive connection timeout when it is shorter.

Review effort: Balanced

@github-actions

Copy link
Copy Markdown

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

86%


📈 Total Lines Covered: 11552 out of 13369
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

  • mssql_python/pybind/connection/connection.cpp (100%)

Summary

  • Total: 4 lines
  • Missing: 0 lines
  • Coverage: 100%

📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.performance_counter.hpp: 0.7%
mssql_python.pybind.logger_bridge.cpp: 57.9%
mssql_python.pybind.ddbc_bindings.h: 65.5%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python._native_fetch.py: 77.2%
mssql_python.__init__.py: 80.8%
mssql_python.pybind.row_mapping_cache.hpp: 81.5%
mssql_python.pybind.ddbc_bindings.cpp: 82.4%
mssql_python.pybind.connection.connection_pool.cpp: 82.5%
mssql_python.pybind.connection.connection.cpp: 83.1%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

@jahnvi480
Jahnvi Thakkar (jahnvi480) merged commit c4b17b2 into main Nov 13, 2026
37 checks passed
Jahnvi Thakkar (jahnvi480) added a commit that referenced this pull request Nov 18, 2026
[AB#50320](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/50320)

### Summary

Prepare mssql-python 1.18.0 using the approved customer-facing change
inventory since v1.17.0.

#### Enhancements

- Accept APP/Application Name across synchronous, async and bulk-copy
paths; note the async/bulk-copy default application-name change to
MSSQL-Python (#884).
- Reduce row-to-dictionary, single-row fetch, output-converter batch and
fetchmany(1) text-processing overhead (#847, #858, #852, #891).
- Cache single-pass pyformat conversion and retain compatible parameter
bindings for prepared-statement reuse (#888, #886).
- Include mssql-python-rs 0.5.0 improvements: Rust-backed execution,
macOS Strict TLS and table-valued parameters in the opt-in Rust ODBC
provider (#896).

#### Bug Fixes

- Avoid unsupported isolation reset when closing pooled Azure Synapse
connections (#889).
- Respect explicit positive connection timeouts during pooled checkout
(#897).
- Coordinate Arrow reader cross-thread shutdown/cancellation (#892).
- Preserve SQL literal, identifier, comment and escaped-percent behavior
during pyformat conversion (#888).
- Include Rust-backed timeout, prepared-statement lifetime/cancellation,
isolation-change, small-stack connection, streaming-order and
SQL_VARIANT decoding fixes (#896).

#### Version

- Bump mssql_python.__version__ and setup.py from 1.17.0 to 1.18.0.
- Replace the previous PyPI highlights with the approved 1.18.0
inventory.
- Change exactly three release files; no runtime implementation or
dependency-pin changes in this PR.

### Validation

- Passed: pinned full-directory Black check, staged Python formatting
hook, release-version/highlights/approved-PR inventory checks, and git
diff --check.
- Not run locally: native rebuild and full integration suite. The
isolated project environment lacks runtime/test dependencies and
DB_CONNECTION_STRING is unset. No integration-test success is claimed;
release qualification remains required.

### Release gates

- Keep this PR unmerged until the required PyPI and Conda
release/verification gates complete.
- Rust dependency verified: mssql-python-rs==0.5.0 was built
successfully by ADO build 191702 from stable commit 2f6ab0fa…. Release
run 191738 successfully verified/staged and published the wheels through
ESRP. All nine wheels are non-yanked on PyPI, and their advertised
SHA256 digests match the staging log. There is no wheel-build or
publication blocker. The overall release run failed on Guardian findings
and dependency-update automation; any required Guardian disposition
remains separate and unresolved.
- Rust release-source comparison: 0.4.0 at
0c3e3c1436b1234d4e838087ff11140ba68b43a5 to 0.5.0 at
2f6ab0faf2a3a4dbad7dc8f0c4cfe2980eabf41d, verified against version
declarations and ADO release sources.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jahnvi Thakkar <61936179+jahnvi480@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: small Minimal code update

3 participants