Skip to content

Commit

Permalink
add stack trace to getConn
Browse files Browse the repository at this point in the history
  • Loading branch information
shanth96 committed Oct 25, 2024
1 parent f10e224 commit 71c07c5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions go/vt/topo/zk2topo/zk_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"math/rand"
"net"
"os"
"runtime"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -288,6 +289,8 @@ func (c *ZkConn) getConn(ctx context.Context) (*zk.Conn, error) {
defer c.mu.Unlock()

if c.conn == nil {
stack := stackTrace()
log.Warningf("getConn: %s Stack: %v", c.addr, stack)
conn, events, err := dialZk(ctx, c.addr)
if err != nil {
return nil, err
Expand All @@ -299,6 +302,25 @@ func (c *ZkConn) getConn(ctx context.Context) (*zk.Conn, error) {
return c.conn, nil
}

func stackTrace() []string {
pc := make([]uintptr, 10)
n := runtime.Callers(0, pc)
if n == 0 {
return []string{}
}
pc = pc[:n]
frames := runtime.CallersFrames(pc)
stack := []string{}
for {
frame, more := frames.Next()
if !more {
break
}
stack = append(stack, fmt.Sprintf("%s (%s:%d)", frame.Function, frame.File, frame.Line))
}
return stack
}

// maybeAddAuth calls AddAuth if the `-topo_zk_auth_file` flag was specified
func (c *ZkConn) maybeAddAuth(ctx context.Context) {
if authFile == "" {
Expand Down

0 comments on commit 71c07c5

Please sign in to comment.