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

SFTP Teardown failure #415

Open
holmanb opened this issue Sep 12, 2024 · 4 comments
Open

SFTP Teardown failure #415

holmanb opened this issue Sep 12, 2024 · 4 comments

Comments

@holmanb
Copy link
Member

holmanb commented Sep 12, 2024

When collecting logs it looks like the instance teardown path recently (within the last month) started throwing an unhandled exception in the failure path. I see the following traceback in cloud-init integration tests on failure.

--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.12/logging/__init__.py", line 1163, in emit
    stream.write(msg + self.terminator)
ValueError: I/O operation on closed file.
Call stack:
  File "/home/runner/work/cloud-init/cloud-init/.tox/integration-tests-ci/lib/python3.12/site-packages/pycloudlib/instance.py", line 204, in __del__
    self._sftp_client.close()
  File "/home/runner/work/cloud-init/cloud-init/.tox/integration-tests-ci/lib/python3.12/site-packages/paramiko/sftp_client.py", line 194, in close
    self._log(INFO, "sftp session closed.")
  File "/home/runner/work/cloud-init/cloud-init/.tox/integration-tests-ci/lib/python3.12/site-packages/paramiko/sftp_client.py", line 182, in _log
    super()._log(
  File "/home/runner/work/cloud-init/cloud-init/.tox/integration-tests-ci/lib/python3.12/site-packages/paramiko/sftp.py", line 169, in _log
    self.logger.log(level, msg, *args)
Message: '[chan %s] sftp session closed.'
Arguments: ('8',)
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.12/logging/__init__.py", line 1163, in emit
    stream.write(msg + self.terminator)
ValueError: I/O operation on closed file.
Call stack:
  File "/home/runner/work/cloud-init/cloud-init/.tox/integration-tests-ci/lib/python3.12/site-packages/paramiko/sftp_client.py", line 194, in close
    self._log(INFO, "sftp session closed.")
  File "/home/runner/work/cloud-init/cloud-init/.tox/integration-tests-ci/lib/python3.12/site-packages/paramiko/sftp_client.py", line 182, in _log
    super()._log(
  File "/home/runner/work/cloud-init/cloud-init/.tox/integration-tests-ci/lib/python3.12/site-packages/paramiko/sftp.py", line 169, in _log
    self.logger.log(level, msg, *args)
Message: '[chan %s] sftp session closed.'
Arguments: ('11',)
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.12/logging/__init__.py", line 1163, in emit
    stream.write(msg + self.terminator)
ValueError: I/O operation on closed file.
Call stack:
  File "/home/runner/work/cloud-init/cloud-init/.tox/integration-tests-ci/lib/python3.12/site-packages/pycloudlib/instance.py", line 204, in __del__
    self._sftp_client.close()
  File "/home/runner/work/cloud-init/cloud-init/.tox/integration-tests-ci/lib/python3.12/site-packages/paramiko/sftp_client.py", line 194, in close
    self._log(INFO, "sftp session closed.")
  File "/home/runner/work/cloud-init/cloud-init/.tox/integration-tests-ci/lib/python3.12/site-packages/paramiko/sftp_client.py", line 182, in _log
    super()._log(
  File "/home/runner/work/cloud-init/cloud-init/.tox/integration-tests-ci/lib/python3.12/site-packages/paramiko/sftp.py", line 169, in _log
    self.logger.log(level, msg, *args)
Message: '[chan %s] sftp session closed.'
Arguments: ('9',)
@a-dubs
Copy link
Collaborator

a-dubs commented Sep 12, 2024

So I did some digging, and this seems to be a known issue with pytest prematurely closing the stream for logging:
pytest-dev/pytest#5502

Was able to find some other GH projects that had a similar issue and were able to implement a easy fix:
scylladb/scylla-cluster-tests#6001

@holmanb
Copy link
Member Author

holmanb commented Sep 12, 2024

So I did some digging, and this seems to be a known issue with pytest prematurely closing the stream for logging: pytest-dev/pytest#5502

Was able to find some other GH projects that had a similar issue and were able to implement a easy fix: scylladb/scylla-cluster-tests#6001

Thanks for digging @a-dubs. It's good to know that this option exists, but I'm a little hesitant to just silence logging exceptions, even if it is in the final cleanup. This could hide future bugs.

I think what is happening is the logger is getting torn down by pytest, and then the final integration instance gets garbage collected which triggers __del__(), which then barfs when it tries to log on sftp close.

For now I think that we can just manually call __del__() after each test in integration tests to prevent this shutdown mess, but long term we should probably move this out of __del__(), but that requires API changes.

@aciba90
Copy link
Collaborator

aciba90 commented Sep 27, 2024

@holmanb, @a-dubs: was this fixed with canonical/cloud-init#5698?

@holmanb
Copy link
Member Author

holmanb commented Sep 27, 2024

@holmanb, @a-dubs: was this fixed with canonical/cloud-init#5698?

Locally for me, yes, but I still see it failing in CI so I guess not.

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

No branches or pull requests

3 participants