-
Notifications
You must be signed in to change notification settings - Fork 20
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
SSHExecutor respects MaxSessions #218
Conversation
Codecov Report
@@ Coverage Diff @@
## master #218 +/- ##
=======================================
Coverage 99.55% 99.55%
=======================================
Files 41 41
Lines 1789 1810 +21
=======================================
+ Hits 1781 1802 +21
Misses 8 8
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
Thanks for the improvement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like the probing but after a little research I also did not find another way to get the max sessions.
So I think the changes are fine!
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for improving the ssh connection handling. I have a few questions concerning the implementation and a request to further improve unittesting before the approval. Could you take this into account, please?
92298f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your contribution and applying the suggested changes. Everything looks good now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. 👍
You also get bonus points from me
def test_max_sessions(self): | ||
with self.subTest(sessions="default"): | ||
self.assertEqual( | ||
DEFAULT_MAX_SESSIONS, run_async(probe_max_session, MockConnection()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is idea behind this test?
Isn't it automatically successful?
Or am I misunderstanding something here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a sanity test that the Mock/probe behaves as expected. Other tests rely on the default as well, so if they fail this test reveals whether the issue is with the default or the other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It tests the functionality of the probe_max_session
function defined in
tardis/tardis/utilities/executors/sshexecutor.py
Lines 15 to 31 in 2d31c69
async def probe_max_session(connection: asyncssh.SSHClientConnection): | |
""" | |
Probe the sshd `MaxSessions`, i.e. the multiplexing limit per connection | |
""" | |
sessions = 0 | |
# It does not actually matter what kind of session we open here, but: | |
# - it should stay open without a separate task to manage it | |
# - it should reliably and promptly clean up when done probing | |
# `create_process` is a bit heavy but does all that. | |
async with AsyncExitStack() as aes: | |
try: | |
while True: | |
await aes.enter_context(await connection.create_process()) | |
sessions += 1 | |
except asyncssh.ChannelOpenError: | |
pass | |
return sessions |
sessions += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay thanks. That makes perfectly sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This PR changes
SSHExecutor
to use at mostMaxSessions
at once.MaxSessions
via probingThis is a rather straightforward implementation of step 1 in #217. After opening a new connection, it is probed until
ChannelOpenError
to deduce the remoteMaxSessions
. This limit is then enforced using a Semaphore on accessing the connection, queueing additional requests.The large diff of
run_command
is because the Semaphore logic works best with a context manager.