Add mutex to pingResponse map to prevent panics with Go>1.5.
@@ -66,6 +66,7 @@ var netMutex *sync.Mutex
var totalNetworkMessagesSent uint32
var pingResponse map[string]time.Time // Last time an IP responded to an "echo" response.
+var pingResponseMutex sync.RWMutex // For versions of Go after 1.6 we need to protect this map from concurrent reads & writes
const (
NETWORK_GDL90_STANDARD = 1
@@ -140,6 +141,8 @@ func getDHCPLeases() (map[string]string, error) {
func isSleeping(k string) bool {
ipAndPort := strings.Split(k, ":")
// No ping response. Assume disconnected/sleeping device.
+ pingResponseMutex.RLock()
+ defer pingResponseMutex.RUnlock()
if lastPing, ok := pingResponse[ipAndPort[0]]; !ok || stratuxClock.Since(lastPing) > (10*time.Second) {
return true
}
@@ -293,6 +296,8 @@ func getNetworkStats() {
continue
}
ip := ipAndPort[0]
+ pingResponseMutex.RLock()
+ defer pingResponseMutex.RUnlock()
if pingRespTime, ok := pingResponse[ip]; ok {
// Don't count the ping time if it is the same as stratuxClock epoch.
// If the client has responded to a ping in the last 15 minutes, count it as "connected" or "recent".
@@ -513,7 +518,9 @@ func sleepMonitor() {
// Look for echo replies, mark it as received.
if msg.Type == ipv4.ICMPTypeEchoReply {
+ pingResponseMutex.Lock()
pingResponse[ip] = stratuxClock.Time
+ pingResponseMutex.Unlock()
continue // No further processing needed.
}
