Skip to content

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

Description

@paulmartinwork

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions