-
Notifications
You must be signed in to change notification settings - Fork 133
fix: Adding Python shutdown check in _close to fix sys.meta_path is None error #730
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug where closing a Databricks SQL connection during Python shutdown would raise an error due to sys.meta_path being None. The fix adds a shutdown detection mechanism and suppresses error logging when Python is shutting down.
Changes:
- Added Python shutdown detection using
sys.meta_path is Nonecheck - Wrapped close operations in try-except blocks to prevent errors during shutdown
- Suppressed error logging when shutdown is detected to avoid spurious error messages
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Check if Python is shutting down | ||
| shutting_down = sys.meta_path is None | ||
|
|
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shutdown check variable is computed once at the beginning of _close, but Python shutdown state could change during the execution of this method. Consider checking sys.meta_path is None directly in each exception handler for more accurate shutdown detection.
| try: | ||
| cursor.close() | ||
| except Exception: | ||
| if not shutting_down: | ||
| logger.debug("Error closing cursor during connection close", exc_info=True) |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching bare Exception is too broad and could mask unexpected errors during normal operation. Consider catching specific exceptions or at minimum using except Exception as e: to log the exception details when not shutting down.
| try: | ||
| TelemetryClientFactory.close(host_url=self.session.host) | ||
| except Exception: | ||
| if not shutting_down: | ||
| logger.debug("Error closing telemetry client", exc_info=True) |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching bare Exception is too broad and could mask unexpected errors during normal operation. Consider catching specific exceptions or at minimum using except Exception as e: to log the exception details when not shutting down.
| try: | ||
| self.http_client.close() | ||
| except Exception: | ||
| if not shutting_down: | ||
| logger.debug("Error closing HTTP client", exc_info=True) |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching bare Exception is too broad and could mask unexpected errors during normal operation. Consider catching specific exceptions or at minimum using except Exception as e: to log the exception details when not shutting down.
|
@msrathore-db Please review this PR, it resolves the following error that we are seeing. Thx |
When are you observing this error. Can you provide repro steps? |
I am observing this issue when setting: |
What type of PR is this?
Description
This PR adds Python shutdown check in _close function to avoid this error:
ERROR:Attempt to close session raised a local exception: sys.meta_path is None, Python is likely shutting downHow is this tested?
Related Tickets & Documents