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

Daniel Goertzen <>
Fri Apr 13 23:28:54 CEST 2012


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/20120413/8059c48a/attachment.html>


More information about the erlang-bugs mailing list