Commit fb0e7c1
authored
FIX: Ensure graceful cleanup of connection pooling to avoid application hang (#120)
### ADO Work Item Reference
<!-- Insert your ADO Work Item ID below (e.g. AB#37452) -->
>
[AB#37851](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/37851)
-------------------------------------------------------------------
### Summary
<!-- Insert your Copilot Generated Summary below -->
This pull request introduces enhancements to the connection pooling
system in the `mssql_python` module, focusing on resource cleanup during
application shutdown. The key changes include adding functionality to
close all connection pools gracefully and ensuring pooling is disabled
automatically when the program exits.
### Enhancements to connection pooling:
* **Automatic resource cleanup on shutdown**:
- Added an `atexit` hook in `mssql_python/pooling.py` to call
`ddbc_bindings.close_pooling()` when the program exits, ensuring
connection pools are closed properly.
* **New `close` method for `ConnectionPool`**:
- Implemented a method in `connection_pool.cpp` to close all connections
in a pool, releasing resources safely. Connections are disconnected in a
loop, and exceptions during disconnection are logged.
- Declared the new `close` method in `connection_pool.h`.
* **New `closePools` method for `ConnectionPoolManager`**:
- Added functionality in `connection_pool.cpp` to iterate through all
pools managed by `ConnectionPoolManager` and close them. The `_pools`
map is cleared afterward.
- Declared the `closePools` method in `connection_pool.h`.
### Integration with Python bindings:
* **Python binding for `close_pooling`**:
- Added a new Python-accessible function `close_pooling` in
`ddbc_bindings.cpp`, which invokes `ConnectionPoolManager::closePools()`
to close all connection pools from the Python layer.
These changes improve the robustness of the connection pooling system by
ensuring resources are properly released during shutdown, preventing
potential memory leaks or dangling connections.
<!--
### PR Title Guide
> For feature requests
FEAT: (short-description)
> For non-feature requests like test case updates, config updates ,
dependency updates etc
CHORE: (short-description)
> For Fix requests
FIX: (short-description)
> For doc update requests
DOC: (short-description)
> For Formatting, indentation, or styling update
STYLE: (short-description)
> For Refactor, without any feature changes
REFACTOR: (short-description)
> For release related changes, without any feature changes
RELEASE: #<RELEASE_VERSION> (short-description)
-->1 parent 94d5387 commit fb0e7c1
File tree
4 files changed
+43
-1
lines changed- mssql_python
- pybind
- connection
4 files changed
+43
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
86 | 105 | | |
87 | 106 | | |
88 | 107 | | |
| |||
110 | 129 | | |
111 | 130 | | |
112 | 131 | | |
113 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
49 | 55 | | |
50 | 56 | | |
51 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2109 | 2109 | | |
2110 | 2110 | | |
2111 | 2111 | | |
| 2112 | + | |
2112 | 2113 | | |
2113 | 2114 | | |
2114 | 2115 | | |
| |||
0 commit comments