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

Add option for keep-alive messages #12

Open
belak opened this issue Feb 3, 2017 · 6 comments
Open

Add option for keep-alive messages #12

belak opened this issue Feb 3, 2017 · 6 comments

Comments

@belak
Copy link
Collaborator

belak commented Feb 3, 2017

Pretty self explanatory. Just sending keepalive@whatever as a request which needs a reply is enough to get both sides to send a little data to keep the connection living. openssh uses keepalive@openssh (or something very similar) this way.

@progrium
Copy link
Contributor

progrium commented Feb 3, 2017

👍

@shazow
Copy link
Member

shazow commented Mar 23, 2019

@belak
Copy link
Collaborator Author

belak commented Mar 23, 2019

That looks almost identical to how I've done it in the past as well... Though my personal preference is to do it at the connection level so you don't need separate keep-alives for every channel.

@9072997
Copy link

9072997 commented Dec 11, 2020

you can use TCP keepalives for this relatively easily

err = ssh.ListenAndServe(
	":22",
	nil,
	ssh.WrapConn(func(s ssh.Context, conn net.Conn) net.Conn {
		conn.(*net.TCPConn).SetKeepAlive(true)
		conn.(*net.TCPConn).SetKeepAlivePeriod(time.Second * 100)
		return conn
	}),
)

@progrium
Copy link
Contributor

that's pretty cool. i think people avoid tcp keepalives though because of proxies but ymmv

@quackduck
Copy link

quackduck commented Oct 27, 2022

you can use TCP keepalives for this relatively easily

err = ssh.ListenAndServe(
	":22",
	nil,
	ssh.WrapConn(func(s ssh.Context, conn net.Conn) net.Conn {
		conn.(*net.TCPConn).SetKeepAlive(true)
		conn.(*net.TCPConn).SetKeepAlivePeriod(time.Second * 100)
		return conn
	}),
)

hmm this didn't work for me

Here's how we do it in ssh-chat: shazow/ssh-chat@ee8d60e/sshd/terminal.go#L87-L104

Somehow even this didn't prevent the connection from being terminated. I checked that the client was receiving the requests, and it was.

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

No branches or pull requests

5 participants