kill stale connections
The weave protocol already effectively performs heartbeating - FetchAll is performed at regular intervals. Hence we can detect stale connections by the lack of receiving any data for approximately that interval (we use x2). We use the same interval to set a time limit on the handshake too, and any subsequent interactions prior to the connection being fully established. Fixes #272.
This commit is contained in:
1 parent
3c50909a49
commit
5ccc753367
2 files changed
+7
-1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user