Skip to content

Commit 34eac8f

Browse files
committed
Fix startuphooks race condition panic
Ensure startup hooks WaitGroup is initialized before starting goroutine that will wait on it Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
1 parent 35f9a35 commit 34eac8f

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

pkg/cli/server/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"path/filepath"
1010
"strings"
11+
"sync"
1112
"time"
1213

1314
systemd "github.com/coreos/go-systemd/v22/daemon"
@@ -602,6 +603,9 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
602603

603604
go cmds.WriteCoverage(ctx)
604605

606+
serverConfig.ControlConfig.Runtime.StartupHooksWg = &sync.WaitGroup{}
607+
serverConfig.ControlConfig.Runtime.StartupHooksWg.Add(len(serverConfig.StartupHooks))
608+
605609
go func() {
606610
if !serverConfig.ControlConfig.DisableETCD {
607611
<-executor.ETCDReadyChan()

pkg/server/server.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"runtime/debug"
99
"strconv"
1010
"strings"
11-
"sync"
1211
"time"
1312

1413
helmchart "github.com/k3s-io/helm-controller/pkg/controllers/chart"
@@ -74,19 +73,14 @@ func StartServer(ctx context.Context, config *Config, cfg *cmds.Server) error {
7473
return pkgerrors.WithMessage(err, "starting kubernetes")
7574
}
7675

77-
wg := &sync.WaitGroup{}
78-
wg.Add(len(config.StartupHooks))
79-
80-
config.ControlConfig.Runtime.StartupHooksWg = wg
81-
8276
shArgs := cmds.StartupHookArgs{
8377
APIServerReady: executor.APIServerReadyChan(),
8478
KubeConfigSupervisor: config.ControlConfig.Runtime.KubeConfigSupervisor,
8579
Skips: config.ControlConfig.Skips,
8680
Disables: config.ControlConfig.Disables,
8781
}
8882
for _, hook := range config.StartupHooks {
89-
if err := hook(ctx, wg, shArgs); err != nil {
83+
if err := hook(ctx, config.ControlConfig.Runtime.StartupHooksWg, shArgs); err != nil {
9084
return pkgerrors.WithMessage(err, "startup hook")
9185
}
9286
}

0 commit comments

Comments
 (0)