[erlang-bugs] ssh close() race condition?

Daniel Goertzen daniel.goertzen@REDACTED
Mon Apr 16 03:40:52 CEST 2012


After reviewing RFC 4254 I can see that there is definitely a bug in
ssh_connection:close().  Looking at the code I see that close() will cause
a SSH_MSG_CHANNEL_CLOSE to be sent, but no state is changed to record that
it happened. When the peer responds with a CLOSE, erlang incorrectly
responds with another CLOSE.

In record "channel" there is a field called "sent_close" that appears to be
intended for recording a locally initiated close(). I suspect this needs to
be set to true in ssh_connection_manager:handle_call({close,...}).

For my application I will work around this by just not calling close().

Dan.

On Fri, Apr 13, 2012 at 4:28 PM, Daniel Goertzen
<daniel.goertzen@REDACTED>wrote:

> I am having problems using erlang ssh against an OpenSSH server.  I am
> establishing an ssh connection and then in a freshly spawned process I will
> do this...
>
>
> command(Conn, Cmd) ->
>    {ok,Chan} = ssh_connection:session_channel(Conn, infinity),
>    success = ssh_connection:exec(Conn, Chan, Cmd, infinity),
>    ... receive data messages until eof...
>    ssh_connection:close(Conn, Chan),
>    ok.
>
>
>
> I run about 6 of these commands sequentially (new process for each), and
> most of the time OpenSSH gets angry with me and drops the whole connection.
>  The error given is...
>
> <barrage of debug messages talking about shutting down channel 1>
> channel_by_id: 1: bad id: channel free
> Disconnecting: Received oclose for nonexistent channel 1.
>
>
>
> But.... if I add a delay before the close() everything seems to work
> perfectly:
>
> command(Conn, Cmd) ->
>    {ok,Chan} = ssh_connection:session_channel(Conn, infinity),
>    success = ssh_connection:exec(Conn, Chan, Cmd, infinity),
>    ... receive data messages until eof...
>    timer:delay(1000),
>    ssh_connection:close(Conn, Chan),
>    ok.
>
>
> Dan.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20120415/b4915493/attachment.htm>


More information about the erlang-bugs mailing list