MarketSquare / MarketSquare/SSHLibrary
close_all_connections() raise RuntimeError when called in a thread
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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