snowflakedb / snowflake-connector-python

Snowflake Connector for Python
https://pypi.python.org/pypi/snowflake-connector-python/
Apache License 2.0
585 stars 468 forks source link

SNOW-996732: improve clean up logic of connection #1898

Closed sfc-gh-aling closed 6 months ago

sfc-gh-aling commented 7 months ago

Please answer these questions before submitting your pull requests. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    the __del__ method is unstable and gets called at random timing. in one of the recent report, we found the __del__ is causing circular import issue.

as a short term fix, we fix by moving away from __del__ method to using atexit to clean up connection at intepreter shutdown time.

long term fix plan here: SNOW-1218851

  1. Fill out the following pre-review checklist:

    • [ ] I am adding a new automated test(s) to verify correctness of my new code
    • [ ] I am adding new logging messages
    • [ ] I am adding a new telemetry message
    • [ ] I am modifying authorization mechanisms
    • [ ] I am adding new credentials
    • [ ] I am modifying OCSP code
    • [ ] I am adding a new dependency
  2. Please describe how your code solves the related issue.

    Please write a short description of how your code change solves the related issue.

sfc-gh-bwarsaw commented 7 months ago

As mentioned in Slack: One thing to keep in mind is that atexit handlers don't get run if os._exit() is called or the process crashes.

sfc-gh-aling commented 7 months ago

thanks @sfc-gh-bwarsaw , this should not be a concern to our connector as we didn't perform critical job during the closing stage.