Subject: Re: Force deallocate all resources within session

Re: Force deallocate all resources within session

From: Peter Stuge <>
Date: Mon, 4 Mar 2013 16:57:50 +0100

Anton Obukhov wrote:
> on session free it attempts to
> send eof when freeing a channel, and performs transport_read, which returns
> EAGAIN and propagates it up the stack. The problem as I see it is that the
> current session and channel closing functions try to do it gracefully by
> means of notifying the server side about their intention to quit the
> connection.

That is the only way to close an SSH2 session. I am sure that you too
have looked at the protocol specifications.

> In my scenario, which can be reproduced by simply unplugging ethernet cable
> from the device running sshd, any attempt to perform communication on the
> channel will result in EAGAIN, cause the network stack sees the network is
> not ready, and SIGPIPE won't come up in the next hour or so. So knowing
> that the connection is now zomby, I want to have a means to destroy the
> session and channel resources without trying to communicate it to the other
> party. Such function would not return EAGAIN in any case, cause it is just
> about freeing structures...

Why don't you solve this problem at a lower layer in your software stack?

Just configure your operating system so that the socket returns an
appropriate error to libssh2.

If libssh2 can not handle such an error, that must of course be fixed.

But I think that libssh2 will handle such errors OK, and that you
will get proper cleanup in that case. Did you try?

Received on 2013-03-04