add a fallback reconnection if no keepalives are recieved within ~24 hours
This commit is contained in:
parent
2cbc8f8496
commit
f5fbce3ee6
@ -2,6 +2,7 @@ package libnmdc
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -28,6 +29,7 @@ type HubConnection struct {
|
||||
connValid bool
|
||||
sentOurHello bool
|
||||
autoReconnect bool
|
||||
lastDataRecieved time.Time
|
||||
|
||||
supports map[string]struct{}
|
||||
}
|
||||
@ -398,6 +400,7 @@ func (this *HubConnection) worker() {
|
||||
}
|
||||
|
||||
if nbytes > 0 {
|
||||
this.lastDataRecieved = time.Now()
|
||||
fullBuffer += string(readBuff[0:nbytes])
|
||||
}
|
||||
}
|
||||
@ -416,6 +419,10 @@ func (this *HubConnection) worker() {
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil && time.Now().Sub(this.lastDataRecieved) > RECONNECT_IF_NO_DATA_RECIEVED_IN {
|
||||
err = fmt.Errorf("No packets recieved since %s, connection presumed lost", this.lastDataRecieved.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
// Maybe we disconnected
|
||||
// Perform this check *last*, to ensure we've had a final shot at
|
||||
// clearing out any queued messages
|
||||
|
@ -14,6 +14,7 @@ const (
|
||||
DEFAULT_HUB_NAME string = "(unknown)"
|
||||
SEND_KEEPALIVE_EVERY time.Duration = 29 * time.Second
|
||||
AUTO_RECONNECT_AFTER time.Duration = 30 * time.Second
|
||||
RECONNECT_IF_NO_DATA_RECIEVED_IN time.Duration = 24 * time.Hour // we expect keepalives wayyyy more frequently than this
|
||||
)
|
||||
|
||||
var rx_protocolMessage *regexp.Regexp
|
||||
|
Loading…
Reference in New Issue
Block a user