From 803ed42dfd6907224c6cc25f032dcbc0c14555a6 Mon Sep 17 00:00:00 2001 From: Kent Ross Date: Mon, 15 Sep 2025 17:53:57 -0700 Subject: [PATCH] only unset the runtime finalizer once per group --- group.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/group.go b/group.go index d1966c3..b619f0f 100644 --- a/group.go +++ b/group.go @@ -164,8 +164,9 @@ func (n *runner) Wait() { } func (n *runner) waitWithoutCanceling() { - n.awaited.Store(true) - runtime.SetFinalizer(n, nil) + if !n.awaited.Swap(true) { + runtime.SetFinalizer(n, nil) // unset the finalizer the first time + } } func (n *runner) getContext() (context.Context, context.CancelCauseFunc) { @@ -247,8 +248,9 @@ func (g *group) Wait() { } func (g *group) waitWithoutCanceling() { - g.awaited.Store(true) - runtime.SetFinalizer(g, nil) + if !g.awaited.Swap(true) { + runtime.SetFinalizer(g, nil) // unset the finalizer the first time + } g.wg.Wait() g.checkPanic() }