Skip to content

Commit

Permalink
Fix ZooKeeper Topology connection locks not being cleaned up correctly (
Browse files Browse the repository at this point in the history
#15757)

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
  • Loading branch information
frouioui committed Apr 22, 2024
1 parent d914e0e commit fc50e07
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 fc50e07

Please sign in to comment.