Thanks.  This diff seems to work for me:<div><br></div><div><div>$ diff -Nbaur ssh_connection.erl.bak ssh_connection.erl</div><div>--- ssh_connection.erl.bak      2012-08-28 08:20:36.340557700 -0500</div><div>+++ ssh_connection.erl  2012-08-28 08:21:50.425465200 -0500</div>
<div>@@ -445,7 +445,7 @@</div><div><br></div><div>     Replies = lists:map(fun({Type, Data}) -></div><div>                                {connection_reply, ConnectionPid,</div><div>-                                channel_data_msg(ChannelId, Type, Data)}</div>
<div>+                                channel_data_msg(Channel#channel.remote_id, Type, Data)}</div><div>                        end, SendList),</div><div>     FlowCtrlMsgs = flow_control(Channel, Cache),</div><div>     {{replies, Replies ++ FlowCtrlMsgs}, Connection};</div>
<div><br></div><div>Dan.</div><div><br><br><div class="gmail_quote">On Tue, Aug 28, 2012 at 1:57 AM, Ingela Anderton Andin <span dir="ltr"><<a href="mailto:ingela.anderton.andin@ericsson.com" target="_blank">ingela.anderton.andin@ericsson.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello!<br>
<br>
Yes that is a bug, thanks for catching it. I will fix it.<br>
<br>
Regards Ingela Erlang OTP/team - Ericsson AB<br>
<br>
Daniel Goertzen wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
Okay, I've found the real bug now. :)<br>
<br>
When Erlang ssh receives a "ssh_msg_channel_window_<u></u>adjust" message and there is outstanding data to transmit, the code will generate "ssh_msg_channel_data" messages with the wrong channel number.  The remote system observes a protocol error and drops the connection.<br>

<br>
The problem is in ssh_connection.erl approximately line 450:<br>
<br></div>
handle_msg(#ssh_msg_channel_<u></u>window_adjust{recipient_<u></u>channel = *ChannelId*,<div class="im"><br>
 bytes_to_add = Add},   #connection{channel_cache = Cache} = Connection,   ConnectionPid, _) -><br>
        #channel{send_window_size = Size} = Channel0 = ssh_channel:cache_lookup(<u></u>Cache, ChannelId), <br>
    {SendList, Channel} =  %% TODO: Datatype 0 ?<br>
update_send_window(Channel0#<u></u>channel{send_window_size = Size + Add},<br>
  0, <<>>, Connection),<br>
        Replies = lists:map(fun({Type, Data}) -> {connection_reply, ConnectionPid,<br></div>
channel_data_msg(*ChannelId*, Type, Data)}  % <-- *bzzt, wrong*<div class="im"><br>
end, SendList),<br>
    FlowCtrlMsgs = flow_control(Channel, Cache),<br>
    {{replies, Replies ++ FlowCtrlMsgs}, Connection};<br>
<br>
<br>
Below is a trace of a channel where I did a ssh_connection:send() of a 13MB binary.  The first window worth of data is correctly sent to channel 2, but the second window of data is incorrectly sent to channel 7.  The remote SSH is OpenSSH.  See bolded sections below<br>

<br>
firmware size 13417472<br>
c{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>connection_reply,<0.135.0>,{<u></u>ssh_msg_channel_open,"session"<u></u>,7,65536,32768,<<0 bytes>>}}]}<br>
al{<0.134.0>,"->",ssh_<u></u>connection,handle_msg,[{ssh_<u></u>msg_channel_open_confirmation,<u></u>7,2,0,32768,<<0 bytes>>},{connection,[{7,{<0.<u></u>145.0>,#Ref<0.0.0.630>}}],<u></u>65583,[],8,undefined,<u></u>undefined,undefined,undefined,<u></u>undefined,undefined,<0.133.0>}<u></u>,<0.135.0>,client]}<br>

ling exec now...<br>
opening channel<br>
{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>channel_requst_reply,{<0.145.<u></u>0>,#Ref<0.0.0.630>},{open,7}}]<u></u>}<br>
calling ssh exec<br>
{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>connection_reply,<0.135.0>,{<u></u>ssh_msg_channel_request,2,"<u></u>exec",true,[<<16 bytes>>]}}]}<br>
{<0.134.0>,"->",ssh_<u></u>connection,handle_msg,[{ssh_<u></u>msg_channel_window_adjust,7,<u></u>87380},{connection,[{7,{<0.<u></u>145.0>,#Ref<0.0.0.634>}}],<u></u>65583,[],8,undefined,<u></u>undefined,undefined,undefined,<u></u>undefined,undefined,<0.133.0>}<u></u>,<0.135.0>,client]}<br>

{<0.134.0>,"->",ssh_<u></u>connection,handle_msg,[{ssh_<u></u>msg_channel_success,7},{<u></u>connection,[{7,{<0.145.0>,#<u></u>Ref<0.0.0.634>}}],65583,[],8,<u></u>undefined,undefined,undefined,<u></u>undefined,undefined,undefined,<u></u><0.133.0>},<0.135.0>,client]}<br>

ca{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>channel_requst_reply,{<0.145.<u></u>0>,#Ref<0.0.0.634>},success}]}<br>
lled send_stdin<br></div>
{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>connection_reply,<0.135.0>,{*<u></u>ssh_msg_channel_data,2*,<<<u></u>32768 bytes>>}}]}<br>
in{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>connection_reply,<0.135.0>,{*<u></u>ssh_msg_channel_data,2*,<<<u></u>32768 bytes>>}}]}<br>
 {<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>connection_reply,<0.135.0>,{*<u></u>ssh_msg_channel_data,2*,<<<u></u>21844 bytes>>}}]}<div class="im"><br>
i{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>flow_control,65583,{channel,"<u></u>session","exec",<0.145.0>,{<0.<u></u>145.0>,#Ref<0.0.0.639>},7,<u></u>65536,32768,false,2,0,32768,<u></u>false,[{0,<<13330092 bytes>>}]},{<0.145.0>,#Ref<0.<u></u>0.0.639>},ok}]}<br>

o loop<br></div>
{<0.134.0>,"->",ssh_<u></u>connection,handle_msg,[{*ssh_<u></u>msg_channel_window_adjust*,*7*<u></u>,124222},{connection,[],65583,<u></u>[],8,undefined,undefined,<u></u>undefined,undefined,undefined,<u></u>undefined,<0.133.0>},<0.135.0><u></u>,client]}<br>

{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>connection_reply,<0.135.0>,{*<u></u>ssh_msg_channel_data,7*,<<<u></u>32768 bytes>>}}]}<br>
io{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>connection_reply,<0.135.0>,{*<u></u>ssh_msg_channel_data,7*,<<<u></u>32768 bytes>>}}]}<div class="im"><br>
 loop got{data,7,1,<<"calling_user 101\nfile_user 0\n">>}<br></div>
{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>connection_reply,<0.135.0>,{*<u></u>ssh_msg_channel_data,7*,<<<u></u>32768 bytes>>}}]}<br>
{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>connection_reply,<0.135.0>,{*<u></u>ssh_msg_channel_data,7*,<<<u></u>25918 bytes>>}}]}<div class="im"><br>
i{<0.134.0>,"->",ssh_<u></u>connection,handle_msg,[{ssh_<u></u>msg_channel_extended_data,7,1,<u></u><<29 bytes>>},{connection,[],65583,<u></u>[],8,undefined,undefined,<u></u>undefined,undefined,undefined,<u></u>undefined,<0.133.0>},<0.135.0><u></u>,client]}<br>

n {<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>channel_data,<0.145.0>,{data,<u></u>7,1,<<29 bytes>>}}]}<br>
io loop<br>
{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>connection_reply,<0.135.0>,{<u></u>ssh_msg_channel_window_adjust,<u></u>2,29}}]}<br>
{<0.134.0>,"->",ssh_<u></u>connection,handle_msg,[{ssh_<u></u>msg_channel_extended_data,7,1,<u></u><<25 bytes>>},{connection,[],65583,<u></u>[],8,undefined,undefined,<u></u>undefined,undefined,undefined,<u></u>undefined,<0.133.0>},<0.135.0><u></u>,client]}<br>

{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>channel_data,<0.145.0>,{data,<u></u>7,1,<<25 bytes>>}}]}<br>
io loop got{data,7,1,<<"proceeding with transfer\n">>}<br>
{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>connection_reply,<0.135.0>,{<u></u>ssh_msg_channel_window_adjust,<u></u>2,25}}]}<br>
in io loop<br></div>
{<0.134.0>,"->",ssh_<u></u>connection,handle_msg,[*{ssh_<u></u>msg_disconnect,2,"Received data for nonexistent channel 7*.",[]},{connection,[],65583,<u></u>[],8,undefined,undefined,<u></u>undefined,undefined,undefined,<u></u>undefined,<0.133.0>},<0.135.0><u></u>,client]}<div class="im">
<br>
{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>channel_data,<0.145.0>,{<u></u>closed,7}}]}<br>
{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>channel_data,<0.132.0>,{<u></u>closed,6}}]}<br>
{<0.134.0>,"->",ssh_<u></u>connection_manager,send_msg,[{<u></u>channel_data,<0.132.0>,{<u></u>closed,5}}]}<br>
<br>
<br>
Dan.<br>
<br></div>
------------------------------<u></u>------------------------------<u></u>------------<br>
<br>
______________________________<u></u>_________________<br>
erlang-bugs mailing list<br>
<a href="mailto:erlang-bugs@erlang.org" target="_blank">erlang-bugs@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-bugs" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-bugs</a><br>
  <br>
</blockquote>
<br>
</blockquote></div><br></div></div>