Skip to content
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

Gateway session can get garbage collected while remote session is still being accessed #282

Open
paulmartinwork opened this issue Feb 2, 2023 · 0 comments

Comments

@paulmartinwork
Copy link

When there are no longer any references the the gateway ssh session but there are to the remote session, the gateway session gets garbage collected too early, resulting in remote sessions failing with the following error:

paramiko.ssh_exception.SSHException: SSH session not active

Here's some code to re-create the issue:

import os
from jumpssh import SSHSession


def get_remote_session():
    user = os.getlogin()
    gateway_session = SSHSession(
        host="127.0.0.1",
        username=user,
    ).open()
    remote_session = gateway_session.get_remote_session(
        host="127.0.0.2",
        username=user,
    )
    return remote_session  # gateway ssh gets garbage collected here, which closes the gateway transport still needed by the remote session


if __name__ == "__main__":
    with get_remote_session() as remote_session:
        remote_session.get_sftp_client().get(
                    ".bashrc",
                    f"{os.path.expanduser('~')}\\Documents\\bashrc.txt"
                )

Which results in:

paramiko.ssh_exception.SSHException: SSH session not active

One possible fix which I've tested as working would be to add a reference to the gateway SSH session inside the jumpssh.SSHSession class. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant