diff --git a/lib/ssh/src/ssh_connection.erl b/lib/ssh/src/ssh_connection.erl index cac00caa0ac2..a2c0357d43e3 100644 --- a/lib/ssh/src/ssh_connection.erl +++ b/lib/ssh/src/ssh_connection.erl @@ -1019,21 +1019,25 @@ handle_msg(#ssh_msg_channel_request{recipient_channel = ChannelId, handle_msg(#ssh_msg_channel_request{recipient_channel = ChannelId, request_type = "exit-signal", want_reply = false, - data = Data}, + data = Data}, #connection{channel_cache = Cache} = Connection0, _, _SSH) -> <> = Data, - Channel = ssh_client_channel:cache_lookup(Cache, ChannelId), - RemoteId = Channel#channel.remote_id, - {Reply, Connection} = reply_msg(Channel, Connection0, - {exit_signal, ChannelId, - binary_to_list(SigName), - binary_to_list(Err), - binary_to_list(Lang)}), - CloseMsg = channel_close_msg(RemoteId), - {[{connection_reply, CloseMsg}|Reply], Connection}; + case ssh_client_channel:cache_lookup(Cache, ChannelId) of + #channel{remote_id = RemoteId} = Channel -> + {Reply, Connection} = reply_msg(Channel, Connection0, + {exit_signal, ChannelId, + binary_to_list(SigName), + binary_to_list(Err), + binary_to_list(Lang)}), + ChannelCloseMsg = channel_close_msg(RemoteId), + {[{connection_reply, ChannelCloseMsg}|Reply], Connection}; + _ -> + %% Channel already closed by peer + {[], Connection0} + end; handle_msg(#ssh_msg_channel_request{recipient_channel = ChannelId, request_type = "xon-xoff",