Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No disconnect handler when using exec_request #85

Closed
AviiNL opened this issue Nov 8, 2022 · 5 comments
Closed

No disconnect handler when using exec_request #85

AviiNL opened this issue Nov 8, 2022 · 5 comments

Comments

@AviiNL
Copy link

AviiNL commented Nov 8, 2022

Behavior is different when using exec_request over a "normal" connection

$ ssh localhost -p2222 test

vs

$ ssh localhost -p2222

When adding the test parameter (which will be put into an exec_request) data isn't received per-keystroke anymore, but only once per new-line, and a ctrl+c on the client side doesn't trigger disconnects or channel close or anything.

How or when do I know on the server when a client closed / disconnected the session when they supply an argument using exec_request?

@Eugeny
Copy link
Member

Eugeny commented Nov 8, 2022

You're experiencing the difference between having a TTY and not. When a TTY is allocated, the SSH client will send the keystrokes immediately and supply additional information such as terminal size.

With OpenSSH, ssh <host> defaults to having a allocating PTY when the client itself running in a terminal, and ssh <host> <command> defaults to working without one. You can override both:

  • ssh -T <host> - shell without a TTY
  • ssh -t <host> <command> - exec with a TTY

@Eugeny Eugeny closed this as completed Nov 8, 2022
@Eugeny
Copy link
Member

Eugeny commented Nov 8, 2022

P.S. ctrl-c will send a signal instead when no PTY is allocated

@AviiNL
Copy link
Author

AviiNL commented Nov 8, 2022

Thanks for the quick response! :)

I am logging signals using

fn signal(self, channel: ChannelId, signal_name: russh::Sig, session: Session) -> Self::FutureUnit {
    info!("Signal: {} {:?}", channel, signal_name);
    self.finished(session)
}

but nothing is coming in, the ssh client just drops back to shell..

Unfortunately because of current (already running) client implementations I can't add a -t to the client requests.

I'm working on re-writing my personal proxy server from typescript to rust, so I can't change how to the clients interacts with the server.

I would at the very least expect a channel_close when a client disconnects, since a channel is opened via channel_open_session, Or am I misunderstanding how this should work?

@Eugeny
Copy link
Member

Eugeny commented Nov 8, 2022

It's possible that your client just kills the connection without sending a signal or a channel_close message - in this case you can implement Drop for your handler - russh will drop it when the connection ends.

@AviiNL
Copy link
Author

AviiNL commented Nov 8, 2022

Hah. how did I not think of that.
Yes, implementing drop does trigger when the client disconnects.

Thanks a bunch! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants