diff --git a/router/connection.go b/router/connection.go index 9ff2e303..2388a284 100644 --- a/router/connection.go +++ b/router/connection.go @@ -285,8 +285,8 @@ func (conn *LocalConnection) handshake(acceptNewPeer bool) error { // ourself. Only when we add this connection to the conn.local // peer will it be visible from multiple go-routines. tcpConn := conn.TCPConn - tcpConn.SetKeepAlive(true) tcpConn.SetLinger(0) + conn.extendReadDeadline() enc := gob.NewEncoder(tcpConn) @@ -428,6 +428,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder, usingPassword bool var err error for { var msg []byte + conn.extendReadDeadline() if conn.CheckFatal(decoder.Decode(&msg)) != nil { return } @@ -501,6 +502,10 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder, usingPassword bool } } +func (conn *LocalConnection) extendReadDeadline() { + conn.TCPConn.SetReadDeadline(time.Now().Add(ReadTimeout)) +} + // Heartbeats // Heartbeating serves two purposes: a) keeping NAT paths alive, and diff --git a/router/consts.go b/router/consts.go index ae9fa46b..92245167 100644 --- a/router/consts.go +++ b/router/consts.go @@ -22,6 +22,7 @@ const ( SlowHeartbeat = 10 * time.Second FetchAllInterval = 30 * time.Second FragTestInterval = 5 * time.Minute + ReadTimeout = 2 * FetchAllInterval PMTUVerifyAttempts = 8 PMTUVerifyTimeout = 10 * time.Millisecond // gets doubled with every attempt MaxDuration = time.Duration(math.MaxInt64)