MarketSquare / MarketSquare/SSHLibrary

close_all_connections() raise RuntimeError when called in a thread

Open
#419 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
167
Forks
145
PR merge metrics
No merged PRs in 30d

Description

In my code, SSHLibrary used like below and this code is run by another thread:
```python
SSHLibrary(...).open_connection(...)
# do something here
SSHLibrary.close_all_connections()
```

This raise exception:
```python
File "/p4_ws/doyou89.jung/workspace/projects/cosmos/.venv/lib/python3.8/site-packages/SSHLibrary/library.py", line 765, in close_all_connections
self._connections.close_all()
File "/p4_ws/doyou89.jung/workspace/projects/cosmos/.venv/lib/python3.8/site-packages/SSHLibrary/sshconnectioncache.py", line 27, in close_all
connection.close()
File "/p4_ws/doyou89.jung/workspace/projects/cosmos/.venv/lib/python3.8/site-packages/SSHLibrary/pythonclient.py", line 302, in close
return super(PythonSSHClient, self).close()
File "/p4_ws/doyou89.jung/workspace/projects/cosmos/.venv/lib/python3.8/site-packages/SSHLibrary/abstractclient.py", line 160, in close
logger.log_background_messages()
File "/p4_ws/doyou89.jung/workspace/projects/cosmos/.venv/lib/python3.8/site-packages/robotbackgroundlogger.py", line 101, in log_background_messages
raise RuntimeError(
RuntimeError: Logging background messages is only allowed from the main thread. Current thread name: schedule_commands_01
```

Because close() method in abstractclient.py do not handle RuntimeError, the code of close() is:
```python
def close(self):
"""Closes the connection."""
self._sftp_client = None
self._scp_transfer_client = None
self._scp_all_client = None
self._shell = None
self.client.close()
try:
logger.log_background_messages()
except AttributeError:
pass
```

I think RuntimeError should be added here.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the close() method in abstractclient.py and trace how close_all_connections() reaches it through sshconnectioncache.py. Reproduce the shown worker-thread sequence and verify that closing the connection no longer raises the RuntimeError from background logging.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.