Skip to content

Commit

Permalink
feat: add printing of the stack trace to healthcheck
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <manan@planetscale.com>
  • Loading branch information
GuptaManan100 committed Feb 25, 2025
1 parent 851b600 commit 8c04a0a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions go/vt/discovery/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"fmt"
"hash/crc32"
"net/http"
"runtime"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -647,6 +648,12 @@ func (hc *HealthCheckImpl) Unsubscribe(c chan *TabletHealth) {
delete(hc.subscribers, c)
}

var printStack = sync.OnceFunc(func() {
buf := make([]byte, 10240) // Allocate buffer large enough
n := runtime.Stack(buf, true)
fmt.Printf("All Goroutines Stack Trace:\n%s\n", buf[:n])
})

func (hc *HealthCheckImpl) broadcast(th *TabletHealth) {
hc.subMu.Lock()
defer hc.subMu.Unlock()
Expand All @@ -657,6 +664,8 @@ func (hc *HealthCheckImpl) broadcast(th *TabletHealth) {
// If the channel is full, we drop the message.
hcChannelFullCounter.Add(1)
log.Warningf("HealthCheck broadcast channel is full for %v, dropping message for %s", subscriber, topotools.TabletIdent(th.Tablet))
// Print the stack trace only once.
printStack()
}
}
}
Expand Down

0 comments on commit 8c04a0a

Please sign in to comment.