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

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2021-03-05 10:19:27 -08:00
parent b14ea68754
commit 602f92ec30

View File

@ -8,6 +8,7 @@
package monitor package monitor
import ( import (
"encoding/json"
"errors" "errors"
"sync" "sync"
"time" "time"
@ -208,9 +209,15 @@ func (m *Mon) debounce() {
m.logf("interfaces.State: %v", err) m.logf("interfaces.State: %v", err)
} else { } else {
m.mu.Lock() m.mu.Lock()
changed := !curState.Equal(m.ifState) oldState := m.ifState
changed := !curState.Equal(oldState)
if changed { if changed {
m.ifState = curState 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 { for _, cb := range m.cbs {
go cb(changed, m.ifState) 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
}