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

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/1456/head
Brad Fitzpatrick 3 years ago
parent b14ea68754
commit 602f92ec30

@ -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
}

Loading…
Cancel
Save