From fc50e07ba81834c2e1fbd7bd5421fe801be4f34d Mon Sep 17 00:00:00 2001 From: Florent Poinsard <35779988+frouioui@users.noreply.github.com> Date: Fri, 19 Apr 2024 18:56:57 -0600 Subject: [PATCH] Fix ZooKeeper Topology connection locks not being cleaned up correctly (#15757) Signed-off-by: Florent Poinsard --- go/vt/topo/zk2topo/lock.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/go/vt/topo/zk2topo/lock.go b/go/vt/topo/zk2topo/lock.go index 974361544a5..5baf1f7f33f 100644 --- a/go/vt/topo/zk2topo/lock.go +++ b/go/vt/topo/zk2topo/lock.go @@ -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 @@ -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