Просмотр исходного кода

wgengine/monitor: log warning if state changes but stringification doesn't

Signed-off-by: Brad Fitzpatrick <[email protected]>
Brad Fitzpatrick 5 лет назад
Родитель
Сommit
602f92ec30
1 измененных файлов с 16 добавлено и 1 удалено
  1. 16 1
      wgengine/monitor/monitor.go

+ 16 - 1
wgengine/monitor/monitor.go

@@ -8,6 +8,7 @@
 package monitor
 
 import (
+	"encoding/json"
 	"errors"
 	"sync"
 	"time"
@@ -208,9 +209,15 @@ func (m *Mon) debounce() {
 			m.logf("interfaces.State: %v", err)
 		} else {
 			m.mu.Lock()
-			changed := !curState.Equal(m.ifState)
+			oldState := m.ifState
+			changed := !curState.Equal(oldState)
 			if changed {
 				m.ifState = curState
+
+				if s1, s2 := oldState.String(), curState.String(); s1 == s2 {
+					m.logf("[unexpected] network state changed, but stringification didn't: %v\nold: %s\nnew: %s\n", s1,
+						jsonSummary(oldState), jsonSummary(curState))
+				}
 			}
 			for _, cb := range m.cbs {
 				go cb(changed, m.ifState)
@@ -225,3 +232,11 @@ func (m *Mon) debounce() {
 		}
 	}
 }
+
+func jsonSummary(x interface{}) interface{} {
+	j, err := json.Marshal(x)
+	if err != nil {
+		return err
+	}
+	return j
+}