From 4ec2bcf8c5474d408dd6464486e5af7b99582338 Mon Sep 17 00:00:00 2001 From: "vitess-bot[bot]" <108069721+vitess-bot[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 09:59:50 -0600 Subject: [PATCH] [release-19.0] Fix ZooKeeper Topology connection locks not being cleaned up correctly (#15757) (#15764) Signed-off-by: Florent Poinsard Co-authored-by: Florent Poinsard <35779988+frouioui@users.noreply.github.com> Co-authored-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