Skip to content

Commit

Permalink
[release-18.0] Fix ZooKeeper Topology connection locks not being clea…
Browse files Browse the repository at this point in the history
…ned up correctly (#15757) (#15763)

Signed-off-by: Florent Poinsard <[email protected]>
Co-authored-by: Florent Poinsard <[email protected]>
  • Loading branch information
vitess-bot[bot] and frouioui authored Apr 22, 2024
1 parent d914e0e commit 1b9ced1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions go/vt/topo/zk2topo/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,22 @@ func (zs *Server) lock(ctx context.Context, dirPath, contents string) (topo.Lock
case context.Canceled:
errToReturn = topo.NewError(topo.Interrupted, nodePath)
default:
errToReturn = vterrors.Wrapf(err, "failed to obtain action lock: %v", nodePath)
errToReturn = vterrors.Wrapf(err, "failed to obtain lock: %v", nodePath)
}

// Regardless of the reason, try to cleanup.
log.Warningf("Failed to obtain action lock: %v", err)
log.Warningf("Failed to obtain lock: %v", err)

if err := zs.conn.Delete(ctx, nodePath, -1); err != nil {
log.Warningf("Failed to close connection :%v", err)
cleanupCtx, cancel := context.WithTimeout(context.Background(), baseTimeout)
defer cancel()

if err := zs.conn.Delete(cleanupCtx, nodePath, -1); err != nil {
log.Warningf("Failed to cleanup unsuccessful lock path %s: %v", nodePath, err)
}

// Show the other locks in the directory
dir := path.Dir(nodePath)
children, _, err := zs.conn.Children(ctx, dir)
children, _, err := zs.conn.Children(cleanupCtx, dir)
if err != nil {
log.Warningf("Failed to get children of %v: %v", dir, err)
return nil, errToReturn
Expand All @@ -115,7 +118,7 @@ func (zs *Server) lock(ctx context.Context, dirPath, contents string) (topo.Lock
}

childPath := path.Join(dir, children[0])
data, _, err := zs.conn.Get(ctx, childPath)
data, _, err := zs.conn.Get(cleanupCtx, childPath)
if err != nil {
log.Warningf("Failed to get first locks node %v (may have just ended): %v", childPath, err)
return nil, errToReturn
Expand Down

0 comments on commit 1b9ced1

Please sign in to comment.