ARM-software / devlib

Library for interaction with and instrumentation of remote devices.
Apache License 2.0
47 stars 78 forks source link

ssh: Reduce number of opened channels #576

Closed douglas-raillard-arm closed 3 years ago

douglas-raillard-arm commented 3 years ago

SSH servers seem to have a maximum number of opened channels, after which paramiko will raise an exception:

Could not open an SSH channel: ChannelException(2, 'Connect failed')

Memoizing the SFTPClient object based on the timeout setting leads to many opened sessions, since the timeout is typically adjusted, e.g. to match the size of the file when pulling an ftrace trace.dat file.

Solve that by memoizing the SFTPClient based only on the connection object, with a maximum number of 1 cached object, and update its timeout setting inplace.