fix: close exec channels to prevent SSH MaxSessions exhaustion - #14
Merged
Conversation
Repeated execute_command calls opened a new channel per command but never closed it, so sessions accumulated until the server's MaxSessions limit rejected new channels (ChannelException: Administratively prohibited) and the connection became unusable. - Close the exec channel in a finally block after reading output - Enable transport keepalive (default 30s) to survive idle timeouts - Retry once on channel-open failure by reconnecting first (safe: the command has not started executing on the remote yet) - Add tests simulating a MaxSessions-limited server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Repeated
execute_commandcalls over the same SSH connection eventually fail with an SSH error (e.g.ChannelException: Administratively prohibited), after which the connection is unusable. This is sshd'sMaxSessionsprotection kicking in.Root cause
Each
exec_command()call opens a new channel on the shared transport, but the channel was never closed after the command finished. Open sessions accumulate (default limit is 10) until the server rejects new channels.Fix (
src/remoteshell_mcp/ssh_client.py)finallyblock after reading stdout/stderr/exit code, releasing the server-side session slot immediatelykeepalive_interval) so idle connections survive firewall/sshd idle timeoutsTests
New
tests/test_ssh_client.py:MaxSessions=2server (previously failed at command 3)SSHException; gives up cleanly after a second failureAll 12 tests pass.