Merge pull request #413 from awh/373_detect_udp_connectivity_breakage
Tear down connections on prolonged loss of UDP heartbeat. Closes #373.
This commit is contained in:
commit
47ef9ff85e
2 files changed
+9
-10
No files matched your search
@@ -44,7 +44,7 @@ type LocalConnection struct {
|
|||||||
stackFrag bool
|
stackFrag bool
|
||||||
effectivePMTU int
|
effectivePMTU int
|
||||||
SessionKey *[32]byte
|
SessionKey *[32]byte
|
||||||
establishedTimeout *time.Timer
|
heartbeatTimeout *time.Timer
|
||||||
heartbeatFrame *ForwardedFrame
|
heartbeatFrame *ForwardedFrame
|
||||||
heartbeat *time.Ticker
|
heartbeat *time.Ticker
|
||||||
fragTest *time.Ticker
|
fragTest *time.Ticker
|
||||||
@@ -270,7 +270,7 @@ func (conn *LocalConnection) run(queryChan <-chan *ConnectionInteraction, finish
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.establishedTimeout = time.NewTimer(EstablishedTimeout)
|
conn.heartbeatTimeout = time.NewTimer(HeartbeatTimeout)
|
||||||
|
|
||||||
if err := conn.queryLoop(queryChan); err != nil {
|
if err := conn.queryLoop(queryChan); err != nil {
|
||||||
conn.log("connection shutting down due to error:", err)
|
conn.log("connection shutting down due to error:", err)
|
||||||
@@ -305,15 +305,12 @@ func (conn *LocalConnection) queryLoop(queryChan <-chan *ConnectionInteraction)
|
|||||||
case CReceivedHeartbeat:
|
case CReceivedHeartbeat:
|
||||||
err = conn.handleReceivedHeartbeat(query.payload.(*net.UDPAddr))
|
err = conn.handleReceivedHeartbeat(query.payload.(*net.UDPAddr))
|
||||||
case CSetEstablished:
|
case CSetEstablished:
|
||||||
conn.establishedTimeout.Stop()
|
|
||||||
err = conn.handleSetEstablished()
|
err = conn.handleSetEstablished()
|
||||||
case CSendProtocolMsg:
|
case CSendProtocolMsg:
|
||||||
err = conn.handleSendProtocolMsg(query.payload.(ProtocolMsg))
|
err = conn.handleSendProtocolMsg(query.payload.(ProtocolMsg))
|
||||||
}
|
}
|
||||||
case <-conn.establishedTimeout.C:
|
case <-conn.heartbeatTimeout.C:
|
||||||
if !conn.established {
|
err = fmt.Errorf("timed out waiting for UDP heartbeat")
|
||||||
err = fmt.Errorf("failed to establish UDP connectivity")
|
|
||||||
}
|
|
||||||
case <-tickerChan(conn.heartbeat):
|
case <-tickerChan(conn.heartbeat):
|
||||||
conn.Forward(true, conn.heartbeatFrame, nil)
|
conn.Forward(true, conn.heartbeatFrame, nil)
|
||||||
case <-tickerChan(conn.fragTest):
|
case <-tickerChan(conn.fragTest):
|
||||||
@@ -338,6 +335,7 @@ func (conn *LocalConnection) handleReceivedHeartbeat(remoteUDPAddr *net.UDPAddr)
|
|||||||
conn.remoteUDPAddr = remoteUDPAddr
|
conn.remoteUDPAddr = remoteUDPAddr
|
||||||
conn.receivedHeartbeat = true
|
conn.receivedHeartbeat = true
|
||||||
conn.Unlock()
|
conn.Unlock()
|
||||||
|
conn.heartbeatTimeout.Reset(HeartbeatTimeout)
|
||||||
if !old {
|
if !old {
|
||||||
if err := conn.handleSendSimpleProtocolMsg(ProtocolConnectionEstablished); err != nil {
|
if err := conn.handleSendSimpleProtocolMsg(ProtocolConnectionEstablished); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -400,8 +398,8 @@ func (conn *LocalConnection) handleShutdown() {
|
|||||||
conn.Router.Ourself.DeleteConnection(conn)
|
conn.Router.Ourself.DeleteConnection(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
if conn.establishedTimeout != nil {
|
if conn.heartbeatTimeout != nil {
|
||||||
conn.establishedTimeout.Stop()
|
conn.heartbeatTimeout.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
stopTicker(conn.heartbeat)
|
stopTicker(conn.heartbeat)
|
||||||
|
|||||||
+2
-1
@@ -19,11 +19,12 @@ const (
|
|||||||
FastHeartbeat = 500 * time.Millisecond
|
FastHeartbeat = 500 * time.Millisecond
|
||||||
SlowHeartbeat = 10 * time.Second
|
SlowHeartbeat = 10 * time.Second
|
||||||
FragTestInterval = 5 * time.Minute
|
FragTestInterval = 5 * time.Minute
|
||||||
EstablishedTimeout = 30 * time.Second
|
|
||||||
ReadTimeout = 1 * time.Minute
|
ReadTimeout = 1 * time.Minute
|
||||||
PMTUVerifyAttempts = 8
|
PMTUVerifyAttempts = 8
|
||||||
PMTUVerifyTimeout = 10 * time.Millisecond // gets doubled with every attempt
|
PMTUVerifyTimeout = 10 * time.Millisecond // gets doubled with every attempt
|
||||||
MaxDuration = time.Duration(math.MaxInt64)
|
MaxDuration = time.Duration(math.MaxInt64)
|
||||||
|
MaxMissedHeartbeats = 3
|
||||||
|
HeartbeatTimeout = MaxMissedHeartbeats * SlowHeartbeat
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
Reference in new issue
Block a user