# Ssh\_client\_channel trapping exits

**URL:** <https://erlangforums.com/t/ssh-client-channel-trapping-exits/2680>\
**Category:** Questions / Help\
**Tags:** erlang-otp, ssh\
**Created:** [June 10, 2023, 8:28am UTC](https://erlangforums.com/t/ssh-client-channel-trapping-exits/2680 "2023-06-10T08:28:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ausimian](https://erlangforums.com/user_avatar/erlangforums.com/ausimian/32/697_2.png) [@ausimian](https://erlangforums.com/u/ausimian)\
**Post date:** [June 10, 2023, 8:28am UTC](https://erlangforums.com/t/ssh-client-channel-trapping-exits/2680/1 "2023-06-10T08:28:36Z")

</div>

I have an [ssh\_cli](https://www.erlang.org/doc/man/ssh.html#type-ssh_cli_daemon_option) handler that implements the [ssh\_server\_channel](https://www.erlang.org/doc/man/ssh_server_channel.html) behaviour, albeit written in Elixir, not Erlang. On receipt of the `pty` message it looks up the capabilities of the terminal by issuing:

```plaintext
System.cmd("infocmp", ["-1", term_name], stderr_to_stdout: true)

```

It does some handling of the _successful_ output from this command, returns from `handle_ssh_msg/2` and then … exits - the client is immediately disconnected from their ssh session 🙁

It took me a little while to work out what was going on but I think it’s this:

- [ssh\_client\_channel](https://github.com/erlang/otp/blob/master/lib/ssh/src/ssh_client_channel.erl) traps exits
- [System.cmd/3](https://hexdocs.pm/elixir/1.14.4/System.html#cmd/3) does not handle its port’s `EXIT` message in its selective receive
- The `EXIT` message is then handled by the `ssh_client_handler` - it hands it off back to my callback module.
- My callback module _doesn’t_ deal with this message
- The `ssh_client_handler` has explicit logic for catching function clauses that don’t deal with the `EXIT` message, wherein it closes the connection.

I _could_ handle the `EXIT` message in `handle_msg/2`, but that doesn’t seem quite right because I don’t know anything about the port itself - its all hidden behind `System.cmd/3`.

Is the better thing to do here just to manage a port myself and, knowing that the hosting process is trapping exits, handle the normal `EXIT` message and throw it away?
