From 3f403d34a4b67e6d5a235cc7b32e92f60ae1a6a9 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Mon, 7 Aug 2023 23:11:20 -0400 Subject: [PATCH] etcd: world: Make sure to check if wg is nil or not We never hit this as far as I know, but might as well be safe. --- etcd/world.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/etcd/world.go b/etcd/world.go index 9ac8e210..6c844b81 100644 --- a/etcd/world.go +++ b/etcd/world.go @@ -74,9 +74,14 @@ func (obj *World) IdealClusterSizeWatch(ctx context.Context) (chan error, error) if err := c.Init(); err != nil { return nil, err } - util.WgFromCtx(ctx).Add(1) + wg := util.WgFromCtx(ctx) + if wg != nil { + wg.Add(1) + } go func() { - defer util.WgFromCtx(ctx).Done() + if wg != nil { + defer wg.Done() + } // This must get closed *after* because it will not finish until // the Watcher returns, because it contains a wg.Wait() in it... defer c.Close() // ignore error