FIX: Connection Pooling Resource Cleanup#268
Merged
bewithgaurav merged 6 commits intomainfrom Oct 8, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request fixes connection pooling resource cleanup by preventing multiple shutdown operations and resource leaks, while also improving test isolation for pooling functionality.
- Adds tracking of pool closure state to prevent double-cleanup operations
- Introduces thread-safe cleanup logic that only runs once when pools are enabled
- Adds a testing utility method to reset pooling state for better test isolation
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
mssql_python/pooling.py |
Implements pool closure tracking and thread-safe cleanup logic to prevent resource leaks |
tests/test_009_pooling.py |
Comprehensive new test suite for pooling functionality including bug fix verification tests |
tests/test_003_connection.py |
Removes pooling tests that were moved to the dedicated pooling test file |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
mssql_python/pooling.pyLines 54-62 54 cls._pools_closed = False
55
56 @atexit.register
57 def shutdown_pooling():
! 58 with PoolingManager._lock:
! 59 if PoolingManager._enabled and not PoolingManager._pools_closed:
! 60 ddbc_bindings.close_pooling()
! 61 PoolingManager._pools_closed = True📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)mssql_python.pybind.connection.connection.cpp: 67.6%
mssql_python.ddbc_bindings.py: 68.5%
mssql_python.pybind.ddbc_bindings.cpp: 69.3%
mssql_python.pybind.connection.connection_pool.cpp: 78.9%
mssql_python.cursor.py: 79.7%
mssql_python.connection.py: 81.7%
mssql_python.helpers.py: 84.7%
mssql_python.auth.py: 85.3%
mssql_python.type.py: 86.8%
mssql_python.pooling.py: 87.5%🔗 Quick Links
|
gargsaumya
approved these changes
Oct 3, 2025
jahnvi480
approved these changes
Oct 6, 2025
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.
Work Item / Issue Reference
Summary
This pull request improves the reliability and testability of the connection pooling logic in
mssql_python/pooling.pyby ensuring that pool shutdown and cleanup operations are properly tracked and only performed once. It also adds a method to reset the pooling state for testing purposes.Connection pool shutdown safety:
_pools_closedflag to thePoolingManagerclass to track whether pools have already been closed, preventing multiple shutdowns and resource leaks.disablemethod and theshutdown_poolingfunction to check_pools_closedbefore attempting to close pools, ensuring cleanup only happens once. [1] [2]Testing support:
_reset_for_testingclass method toPoolingManagerto reset internal state, making it easier to write reliable tests for pooling behavior.