Allow setting timeouts for connection
Specifically for the handshake, requesting a session, starting a command, and connection closing.
Do you have any example of libraries that let you specify all the possible timeouts? Usually there is a high level timeout or two, but SSH has a lot of ones as you mention. Perhaps a Timeout struct than can be passed into our server object.
I don't have any public examples. This comes from our config struct though (all the ones we support internally):
// HandshakeTimeout is the amount of time allowed between connecting and
// successful auth.
HandshakeTimeout time.Duration
// NewChannelTimeout is the amount of time allowed between auth and making
// the first valid channel.
NewChannelTimeout time.Duration
// ChannelRequestTimeout is the amount of time allowed between creating a
// channel and making the first valid request.
ChannelRequestTimeout time.Duration
// ConnectionCloseTimeout is the amount of time allowed between when the
// command finishes running and the connection is forcefully closed.
ConnectionCloseTimeout time.Duration
I realize this won't be used by everyone, or even most people, so I'd be happy to do the work to support most of the features I'm proposing.
What do you think of wrapping these in a struct:
type Timeouts struct {
// HandshakeTimeout is the amount of time allowed between connecting and
// successful auth.
Handshake time.Duration
// NewChannelTimeout is the amount of time allowed between auth and making
// the first valid channel.
NewChannel time.Duration
// ChannelRequestTimeout is the amount of time allowed between creating a
// channel and making the first valid request.
ChannelRequest time.Duration
// ConnectionCloseTimeout is the amount of time allowed between when the
// command finishes running and the connection is forcefully closed.
ConnectionClose time.Duration
}
That works for me. Other notes from our discussion:
-
ConnectionCloseis really only useful if #7 is also done - It may also be useful to have a
ChannelClosetimeout
I have created a pull request to support handshake timeout: #204
I've stumbled over this issue here and i'm wondering if it's also a valid use-case to have a timeout where the server will shutdown if no connection is established within the defined timeout duration?
more context:
we are using https://github.com/owenthereal/upterm which spawn a sshServer (in gliderlabs/ssh speech) on demand.
We are using this in combination with github runners to be able so ssh into a runner, if needed.
At the moment we have written a shell wrapper around upterm to terminate the process if no connection got established.