0 votes
by (150 points)

Hello,

One of our clients sometimes gets an error "Cannot send data because the terminal is not bound to a channel".
The error is thrown immediately when trying to send a text line to a remote host through the VirtualTerminal.

We are using the following code to start the terminal session:

var terminal = ssh.StartVirtualTerminal();

and then

terminal.SendToServer(commandStr); <-- This line sometimes fails!

Unfortunately the stack trace does not contain any useful information to identify possible reasons:

Rebex.TerminalEmulation.TerminalException: Cannot send data because the terminal is not bound to a channel.
at Rebex.TerminalEmulation.VirtualTerminal.SendToServer(String text)

Could you please point me out why this error occurs and how to deal with it?

Thanks in advance!

1 Answer

+1 vote
by (73.6k points)
edited by

It is a little bit misleading error message. It is true, that the terminal is not bound to a channel, however the real cause is probably that the terminal was unbound due to loss of connection.

The terminal is not bound to a channel in 4 cases:

  1. a new instance of terminal, which was never bound
  2. an instance on which Unbind method was just called
  3. an instance on which Dispose method was called
  4. an instance, which underlying channel was undound due to connection loss

From your description, we can eliminate point 1 (ssh.StartVirtualTerminal() creates bound terminal).

If you are sure that you didn't call Unbind or Dispose methods before you call SendToServer method, the last possible explanation is point 4.

Basically, it can arises in 3 situations:

  1. connection close was requested by client e.g. by issuing exit command
  2. connection was close forcibly by server e.g. the server encountered an error and closed the existing connection
  3. connection was interrupted due to network failure

To detect any of the above connection closures please use the VirtualTerminal.Disconnected event.

However, I improved exception message to better describe the situation (EDIT: it was included in release 2017 R2).

If you have doubts about the cause of error in your case, please send us the Debug log of your communication (to support@rebex.net). I will analyze it for you.

by (150 points)
Thank you, Lukas, for detailed explanation.
I think my case is 4.
I will try to use the VirtualTerminal.Disconnected (damn, how could I miss it?).
...