Skip to content
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

[SNOW-1669128]: Ensure SnowflakeConnection atexit function is registered on import #2061

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sfc-gh-rdurrani
Copy link

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.

    Fixes #SNOW-1669128

  2. 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
  3. Please describe how your code solves the related issue.

Previously, the close_at_exit function for the SnowflakeConnection object
was registered with the atexit module during initialization of a SnowflakeConnection object.
This caused the Snowpark Session object's atexit function to be registered before the
SnowflakeConnection's object when the Session was made without an existing SnowflakeConnection
object, because the SnowflakeConnection object's atexit was only registered after it was initialized
whereas the Snowpark Session object's atexit was registered when the file was imported. During the
atexit for the Snowpark Session, it attempts to send telemetry regarding cleanup operations, but since
it's connection is already closed, it fails to send the telemetry. Moving the registration of the atexit
function here means that it will happen when the SnowflakeConnection object is imported - and so the
Snowpark Session's atexit function will be registered after, and the order will be correct.

  1. (Optional) PR for stored-proc connector:

@sfc-gh-rdurrani
Copy link
Author

Do folks think that this should be ported to SP? I checked the connection.py file there, and there doesn't seem to be an import of atexit, so I'm thinking it shouldn't be ported, but wanted to double check!

# it's connection is already closed, it fails to send the telemetry. Moving the registration of the atexit
# function here means that it will happen when the SnowflakeConnection object is imported - and so the
# Snowpark Session's atexit function will be registered after, and the order will be correct.
def _close_connection_at_exit(snowflake_connection: SnowflakeConnection):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this parameter passed in from?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thank you! I've added a variable to track active connections - would this work, or would you suggest another workaround (e.g. perhaps by making a class method to register the atexit function in the SnowflakeConnection object, and calling it from the Snowpark Session object before registering its own atexit function)?

@sfc-gh-jkew
Copy link

I would be hesitant to change the atexit behavior here, as opposed to simply removing the warning to fix a failed telemetry send. This may actually be the root cause; but I also think it's a more dangerous change considering the initial problem ( a warning ).

I might be convinced otherwise though - maybe I'm just being paranoid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants