From 602f92ec30350cc8363252d9d642285f8ee4c929 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 5 Mar 2021 10:19:27 -0800 Subject: [PATCH] wgengine/monitor: log warning if state changes but stringification doesn't Signed-off-by: Brad Fitzpatrick --- wgengine/monitor/monitor.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/wgengine/monitor/monitor.go b/wgengine/monitor/monitor.go index da99a9d6c..13c28451d 100644 --- a/wgengine/monitor/monitor.go +++ b/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 +}