<div>Okay, I've found the real bug now. :)</div><div><br></div>When Erlang ssh receives a "ssh_msg_channel_window_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.<div>
<br></div><div>The problem is in ssh_connection.erl approximately line 450:</div><div><br></div><div>handle_msg(#ssh_msg_channel_window_adjust{recipient_channel = <b>ChannelId</b>,</div><div><div><span class="Apple-tab-span" style="white-space:pre"> </span> bytes_to_add = Add}, </div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> #connection{channel_cache = Cache} = Connection, </div><div><span class="Apple-tab-span" style="white-space:pre"> </span> ConnectionPid, _) -></div>
<div> </div><div> #channel{send_window_size = Size} = </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Channel0 = ssh_channel:cache_lookup(Cache, ChannelId), </div><div><br></div><div> {SendList, Channel} = %% TODO: Datatype 0 ?</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>update_send_window(Channel0#channel{send_window_size = Size + Add},</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> 0, <<>>, Connection),</div>
<div> </div><div> Replies = lists:map(fun({Type, Data}) -> </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{connection_reply, ConnectionPid,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> channel_data_msg(<b>ChannelId</b>, Type, Data)} % <-- <b>bzzt, wrong</b></div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>end, SendList),</div><div> FlowCtrlMsgs = flow_control(Channel, Cache),</div><div> {{replies, Replies ++ FlowCtrlMsgs}, Connection};</div></div><div>
<br></div><div><br></div><div>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</div>
<div><br></div><div><div>firmware size 13417472</div><div>c{<0.134.0>,"->",ssh_connection_manager,send_msg,[{connection_reply,<0.135.0>,{ssh_msg_channel_open,"session",7,65536,32768,<<0 bytes>>}}]}</div>
<div>al{<0.134.0>,"->",ssh_connection,handle_msg,[{ssh_msg_channel_open_confirmation,7,2,0,32768,<<0 bytes>>},{connection,[{7,{<0.145.0>,#Ref<0.0.0.630>}}],65583,[],8,undefined,undefined,undefined,undefined,undefined,undefined,<0.133.0>},<0.135.0>,client]}</div>
<div>ling exec now...</div><div>opening channel</div><div>{<0.134.0>,"->",ssh_connection_manager,send_msg,[{channel_requst_reply,{<0.145.0>,#Ref<0.0.0.630>},{open,7}}]}</div><div>calling ssh exec</div>
<div>{<0.134.0>,"->",ssh_connection_manager,send_msg,[{connection_reply,<0.135.0>,{ssh_msg_channel_request,2,"exec",true,[<<16 bytes>>]}}]}</div><div>{<0.134.0>,"->",ssh_connection,handle_msg,[{ssh_msg_channel_window_adjust,7,87380},{connection,[{7,{<0.145.0>,#Ref<0.0.0.634>}}],65583,[],8,undefined,undefined,undefined,undefined,undefined,undefined,<0.133.0>},<0.135.0>,client]}</div>
<div>{<0.134.0>,"->",ssh_connection,handle_msg,[{ssh_msg_channel_success,7},{connection,[{7,{<0.145.0>,#Ref<0.0.0.634>}}],65583,[],8,undefined,undefined,undefined,undefined,undefined,undefined,<0.133.0>},<0.135.0>,client]}</div>
<div>ca{<0.134.0>,"->",ssh_connection_manager,send_msg,[{channel_requst_reply,{<0.145.0>,#Ref<0.0.0.634>},success}]}</div><div>lled send_stdin</div><div>{<0.134.0>,"->",ssh_connection_manager,send_msg,[{connection_reply,<0.135.0>,{<b>ssh_msg_channel_data,2</b>,<<32768 bytes>>}}]}</div>
<div>in{<0.134.0>,"->",ssh_connection_manager,send_msg,[{connection_reply,<0.135.0>,{<b>ssh_msg_channel_data,2</b>,<<32768 bytes>>}}]}</div><div> {<0.134.0>,"->",ssh_connection_manager,send_msg,[{connection_reply,<0.135.0>,{<b>ssh_msg_channel_data,2</b>,<<21844 bytes>>}}]}</div>
<div>i{<0.134.0>,"->",ssh_connection_manager,send_msg,[{flow_control,65583,{channel,"session","exec",<0.145.0>,{<0.145.0>,#Ref<0.0.0.639>},7,65536,32768,false,2,0,32768,false,[{0,<<13330092 bytes>>}]},{<0.145.0>,#Ref<0.0.0.639>},ok}]}</div>
<div>o loop</div><div>{<0.134.0>,"->",ssh_connection,handle_msg,[{<b>ssh_msg_channel_window_adjust</b>,<b>7</b>,124222},{connection,[],65583,[],8,undefined,undefined,undefined,undefined,undefined,undefined,<0.133.0>},<0.135.0>,client]}</div>
<div>{<0.134.0>,"->",ssh_connection_manager,send_msg,[{connection_reply,<0.135.0>,{<b>ssh_msg_channel_data,7</b>,<<32768 bytes>>}}]}</div><div>io{<0.134.0>,"->",ssh_connection_manager,send_msg,[{connection_reply,<0.135.0>,{<b>ssh_msg_channel_data,7</b>,<<32768 bytes>>}}]}</div>
<div> loop got{data,7,1,<<"calling_user 101\nfile_user 0\n">>}</div><div>{<0.134.0>,"->",ssh_connection_manager,send_msg,[{connection_reply,<0.135.0>,{<b>ssh_msg_channel_data,7</b>,<<32768 bytes>>}}]}</div>
<div>{<0.134.0>,"->",ssh_connection_manager,send_msg,[{connection_reply,<0.135.0>,{<b>ssh_msg_channel_data,7</b>,<<25918 bytes>>}}]}</div><div>i{<0.134.0>,"->",ssh_connection,handle_msg,[{ssh_msg_channel_extended_data,7,1,<<29 bytes>>},{connection,[],65583,[],8,undefined,undefined,undefined,undefined,undefined,undefined,<0.133.0>},<0.135.0>,client]}</div>
<div>n {<0.134.0>,"->",ssh_connection_manager,send_msg,[{channel_data,<0.145.0>,{data,7,1,<<29 bytes>>}}]}</div><div>io loop</div><div>{<0.134.0>,"->",ssh_connection_manager,send_msg,[{connection_reply,<0.135.0>,{ssh_msg_channel_window_adjust,2,29}}]}</div>
<div>{<0.134.0>,"->",ssh_connection,handle_msg,[{ssh_msg_channel_extended_data,7,1,<<25 bytes>>},{connection,[],65583,[],8,undefined,undefined,undefined,undefined,undefined,undefined,<0.133.0>},<0.135.0>,client]}</div>
<div>{<0.134.0>,"->",ssh_connection_manager,send_msg,[{channel_data,<0.145.0>,{data,7,1,<<25 bytes>>}}]}</div><div>io loop got{data,7,1,<<"proceeding with transfer\n">>}</div>
<div>{<0.134.0>,"->",ssh_connection_manager,send_msg,[{connection_reply,<0.135.0>,{ssh_msg_channel_window_adjust,2,25}}]}</div><div>in io loop</div><div>{<0.134.0>,"->",ssh_connection,handle_msg,[<b>{ssh_msg_disconnect,2,"Received data for nonexistent channel 7</b>.",[]},{connection,[],65583,[],8,undefined,undefined,undefined,undefined,undefined,undefined,<0.133.0>},<0.135.0>,client]}</div>
<div>{<0.134.0>,"->",ssh_connection_manager,send_msg,[{channel_data,<0.145.0>,{closed,7}}]}</div><div>{<0.134.0>,"->",ssh_connection_manager,send_msg,[{channel_data,<0.132.0>,{closed,6}}]}</div>
<div>{<0.134.0>,"->",ssh_connection_manager,send_msg,[{channel_data,<0.132.0>,{closed,5}}]}</div></div><div><br></div><div><br></div><div>Dan.</div><div><br></div>