Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 53
FIX: Fixing segmentation fault issue due to double free on SqlHandle::free in Linux#361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
216a04b528507ea14bb69e970e340ce40210a2b2469329061e8bc380ae23203b2470638be7576bede06ccef4e3ad88c3a5File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,8 +4,11 @@ | ||
| This module initializes the mssql_python package. | ||
| """ | ||
| import atexit | ||
| import sys | ||
| import threading | ||
| import types | ||
| import weakref | ||
| from typing import Dict | ||
| # Import settings from helpers to avoid circular imports | ||
| @@ -67,6 +70,49 @@ | ||
| # Pooling | ||
| from .pooling import PoolingManager | ||
| # Global registry for tracking active connections (using weak references) | ||
| _active_connections = weakref.WeakSet() | ||
subrata-ms marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| _connections_lock = threading.Lock() | ||
| def _register_connection(conn): | ||
| """Register a connection for cleanup before shutdown.""" | ||
| with _connections_lock: | ||
| _active_connections.add(conn) | ||
| def _cleanup_connections(): | ||
| """ | ||
| Cleanup function called by atexit to close all active connections. | ||
| This prevents resource leaks during interpreter shutdown by ensuring | ||
| all ODBC handles are freed in the correct order before Python finalizes. | ||
| """ | ||
| # Make a copy of the connections to avoid modification during iteration | ||
| with _connections_lock: | ||
| connections_to_close = list(_active_connections) | ||
| for conn in connections_to_close: | ||
| try: | ||
| # Check if connection is still valid and not closed | ||
| if hasattr(conn, "_closed") and not conn._closed: | ||
subrata-ms marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # Close will handle both cursors and the connection | ||
| conn.close() | ||
| except Exception as e: | ||
| # Log errors during shutdown cleanup for debugging | ||
| # We're prioritizing crash prevention over error propagation | ||
| try: | ||
| driver_logger.error( | ||
| f"Error during connection cleanup at shutdown: {type(e).__name__}: {e}" | ||
| ) | ||
| except Exception: | ||
| # If logging fails during shutdown, silently ignore | ||
| pass | ||
| # Register cleanup function to run before Python exits | ||
| atexit.register(_cleanup_connections) | ||
| # GLOBALS | ||
| # Read-Only | ||
| apilevel: str = "2.0" | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.