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

fix: force sftp cleanup when done with instance #5698

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

holmanb
Copy link
Member

@holmanb holmanb commented Sep 12, 2024

Proposed Commit Message

fix: force sftp cleanup when done with instance

Force inline sftp closure rather than on garbage collection.
Without this, pytest causes tracebacks because it cleans up the logger
before the final sftp connection is closed, which causes tracebacks
after tests exit.

Additional Context

pytest-dev/pytest#5282
pytest-dev/pytest#5502
canonical/pycloudlib#415

Test steps

I tested the client and class_client fixtures manually by introducing two new classes, with one failing test each, and didn't see any tracebacks nor unexpected failures.

Force inline sftp closure rather than on garbage collection.
Without this, pytest causes tracebacks because it cleans up the logger
before the final sftp connection is closed, which causes tracebacks
after tests pass.
Copy link
Member

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

LGTM!

# paramiko to barf when it logs that the connection is being closed.
#
# Manually run __del__() to prevent this teardown mess.
instance.instance.__del__()
Copy link
Member

Choose a reason for hiding this comment

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

nit: del instance.instance

Copy link
Member Author

Choose a reason for hiding this comment

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

nit: del instance.instance

fyi that's what the original implementation attempted, but it didn't work because del decrements the refcount, which will not necessarily cause the refcount to go to 0, nor will it force the garbage collector to run (which is what invokes __del__()). This really deserved a comment, but since this is somehow happening in CI still, further investigation is required

@holmanb
Copy link
Member Author

holmanb commented Sep 13, 2024

However this weirdly didn't seem to fix the issue in ci (this test run still had the traveback despite passing) and I wasn't able to repro locally with this fix so more digging is required

@holmanb
Copy link
Member Author

holmanb commented Sep 18, 2024

However this weirdly didn't seem to fix the issue in ci (this test run still had the traveback despite passing) and I wasn't able to repro locally with this fix so more digging is required

I'm going to merge this since it resolves the issue locally, I may followup to resolve the issue in CI as well.

@holmanb holmanb merged commit 436126b into canonical:main Sep 18, 2024
21 checks passed
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.

2 participants