Print stacktrace in questionable situations

It would be useful to see what the stack looks like when we get
consecutive watchdog patting failures. We can then try to work out
what's ultimately causing this issue.

Approved-by: Trek Hopton
This commit is contained in:
Saxon Milton 2024-04-07 00:25:03 +00:00 committed by Saxon Nelson-Milton
parent a40faaa23e
commit 66a1687316
3 changed files with 34 additions and 9 deletions

View File

@ -138,6 +138,7 @@ func terminationCallback(m *broadcastManager) func() {
return
}
m.log.Info("successfully saved broadcast manager state on termination signal")
logTrace(m.log.Debug,m.log.Warning)
}
}

View File

@ -92,12 +92,20 @@ func (n *watchdogNotifier) notify() {
n.termCallback()
}()
var consecutiveUnhealthyStates int
for {
const nUnhealthyStatesForTrace = 10
if n.handlersUnhealthy() {
consecutiveUnhealthyStates++
if consecutiveUnhealthyStates >= nUnhealthyStatesForTrace {
logTrace(n.log.Debug,n.log.Warning)
consecutiveUnhealthyStates = 0
}
const unhealthyHandlerWait = 1 * time.Second
time.Sleep(unhealthyHandlerWait)
continue
}
consecutiveUnhealthyStates = 0
<-notifyTicker.C

View File

@ -28,6 +28,7 @@ import (
"fmt"
"net/http"
"strconv"
"runtime"
"bitbucket.org/ausocean/av/codec/codecutil"
"bitbucket.org/ausocean/av/revid"
@ -86,3 +87,18 @@ func isMac(m string) bool {
}
return true
}
type Log func(msg string, args ...interface{})
func logTrace(debug, warning Log){
const (
maxStackTraceSize = 100000
allStacks = true
)
buf := make([]byte, maxStackTraceSize)
n := runtime.Stack(buf, allStacks)
if n > maxStackTraceSize && warning != nil {
warning("stacktrace exceeded buffer size")
}
debug("got stacktrace at termination", "stacktrace", string(buf[:n]))
}