ssh icon indicating copy to clipboard operation
ssh copied to clipboard

Allow setting timeouts for connection

Open belak opened this issue 8 years ago • 7 comments

Specifically for the handshake, requesting a session, starting a command, and connection closing.

belak avatar Feb 03 '17 22:02 belak

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.

progrium avatar Feb 03 '17 22:02 progrium

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

belak avatar Feb 03 '17 22:02 belak

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.

belak avatar Feb 03 '17 22:02 belak

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
}

progrium avatar Feb 03 '17 22:02 progrium

That works for me. Other notes from our discussion:

  • ConnectionClose is really only useful if #7 is also done
  • It may also be useful to have a ChannelClose timeout

belak avatar Feb 03 '17 23:02 belak

I have created a pull request to support handshake timeout: #204

aderouineau avatar Jun 05 '23 17:06 aderouineau

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.

bavarianbidi avatar Oct 10 '23 10:10 bavarianbidi