Skip to content

transports: ssh: disconnect session before freeing it - #4596

Merged
ethomson merged 2 commits into
libgit2:masterfrom
pks-t:pks/ssh-disconnect
Apr 16, 2018
Merged

transports: ssh: disconnect session before freeing it #4596
ethomson merged 2 commits into
libgit2:masterfrom
pks-t:pks/ssh-disconnect

Conversation

@pks-t

@pks-t pks-t commented Mar 27, 2018

Copy link
Copy Markdown
Member

The function ssh_stream_free takes over the responsibility of closing
channels and streams just before freeing their memory, but it does not
do so for the session. In fact, we never disconnect the session
ourselves at all, as libssh2 will not do so itself upon freeing the
structure. Quoting the documentation of libssh2_session_free:

> Frees all resources associated with a session instance. Typically
> called after libssh2_session_disconnect_ex,

The missing disconnect probably stems from a misunderstanding what it
actually does. As we are already closing the TCP socket ourselves, the
assumption was that no additional disconnect is required. But calling
libssh2_session_disconnect will notify the server that we are cleanly
closing the connection, such that the server can free his own resources.

Add a call to libssh2_session_disconnect to fix that issue.


This fixes #3473. After all, it seems to me like the issue report is valid.

The other commit is just swapping out a deprecated function for its newer equivalent.

/cc @carlosmn

pks-t added 2 commits March 27, 2018 15:02
The function `ssh_stream_free` takes over the responsibility of closing
channels and streams just before freeing their memory, but it does not
do so for the session. In fact, we never disconnect the session
ourselves at all, as libssh2 will not do so itself upon freeing the
structure. Quoting the documentation of `libssh2_session_free`:

    > Frees all resources associated with a session instance. Typically
    > called after libssh2_session_disconnect_ex,

The missing disconnect probably stems from a misunderstanding what it
actually does. As we are already closing the TCP socket ourselves, the
assumption was that no additional disconnect is required. But calling
`libssh2_session_disconnect` will notify the server that we are cleanly
closing the connection, such that the server can free his own resources.

Add a call to `libssh2_session_disconnect` to fix that issue.

[1]: https://www.libssh2.org/libssh2_session_free.html
The function `libssh2_session_startup` has been deprecated since libssh2
version 1.2.8 in favor of `libssh2_session_handshake` introduced in the
same version. libssh2 1.2.8 was released in April 2011, so it is already
seven years old. It is available in Debian Wheezy, Ubuntu Trusty and
CentOS 7.4, so the most important and conservative distros already have
it available. As such, it seems safe to just use the new function.
@pks-t pks-t added the backport label Apr 6, 2018
@ethomson

Copy link
Copy Markdown
Member

LGTM, thanks.

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

Successfully merging this pull request may close these issues.

SSH transport never disconnects from server

2 participants