mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-08 11:22:10 +03:00
sshd: Apply read deadline to connection handler (#331)
This should prevent connections from stalling out and eating up file descriptors without ever joining the chat.
This commit is contained in:
parent
1b2a3e97a0
commit
5af617f3b9
2
go.mod
2
go.mod
@ -8,3 +8,5 @@ require (
|
|||||||
golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576
|
golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576
|
||||||
golang.org/x/sys v0.0.0-20190321052220-f7bb7a8bee54
|
golang.org/x/sys v0.0.0-20190321052220-f7bb7a8bee54
|
||||||
)
|
)
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
@ -2,6 +2,7 @@ package sshd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/shazow/rateio"
|
"github.com/shazow/rateio"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
@ -32,6 +33,12 @@ func (l *SSHListener) handleConn(conn net.Conn) (*Terminal, error) {
|
|||||||
conn = ReadLimitConn(conn, l.RateLimit())
|
conn = ReadLimitConn(conn, l.RateLimit())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the connection doesn't write anything back for too long before we get
|
||||||
|
// a valid session, it should be dropped.
|
||||||
|
var handleTimeout = 20 * time.Second
|
||||||
|
conn.SetReadDeadline(time.Now().Add(handleTimeout))
|
||||||
|
defer conn.SetReadDeadline(time.Time{})
|
||||||
|
|
||||||
// Upgrade TCP connection to SSH connection
|
// Upgrade TCP connection to SSH connection
|
||||||
sshConn, channels, requests, err := ssh.NewServerConn(conn, l.config)
|
sshConn, channels, requests, err := ssh.NewServerConn(conn, l.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user