From 2f4cd929ef90d25891fba6e9e39fbb4d951d814c Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Mon, 10 Apr 2023 17:28:23 +0200 Subject: [PATCH] server: fix a race condition during server initialization The call to `registerEnginesForDiskStatsMap` needs to wait until the store IDs are known. Release note: None --- pkg/server/server.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/server/server.go b/pkg/server/server.go index 4a3a78d152dd..c4892a820042 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -1798,6 +1798,13 @@ func (s *Server) PreStart(ctx context.Context) error { // to bypass admission control. s.storeGrantCoords.SetPebbleMetricsProvider(ctx, s.node, s.node) + // Connect the engines to the disk stats map constructor. + // This also needs to wait until after `waitForAdditionalStoreInit` returns, + // as the store IDs may not be known until then. + if err := s.node.registerEnginesForDiskStatsMap(s.cfg.Stores.Specs, s.engines); err != nil { + return errors.Wrapf(err, "failed to register engines for the disk stats map") + } + // Once all stores are initialized, check if offline storage recovery // was done prior to start and record any actions appropriately. logPendingLossOfQuorumRecoveryEvents(workersCtx, s.node.stores) @@ -1938,11 +1945,6 @@ func (s *Server) PreStart(ctx context.Context) error { } } - // Connect the engines to the disk stats map constructor. - if err := s.node.registerEnginesForDiskStatsMap(s.cfg.Stores.Specs, s.engines); err != nil { - return errors.Wrapf(err, "failed to register engines for the disk stats map") - } - if storage.WorkloadCollectorEnabled { if err := s.debug.RegisterWorkloadCollector(s.node.stores); err != nil { return errors.Wrapf(err, "failed to register workload collector with debug server")