diff --git a/changelog/23906.txt b/changelog/23906.txt new file mode 100644 index 000000000000..ed3671dbf421 --- /dev/null +++ b/changelog/23906.txt @@ -0,0 +1,3 @@ +```release-note:bug +core: fix rare panic due to a race condition with metrics collection during seal +``` diff --git a/vault/core_metrics.go b/vault/core_metrics.go index 022e2fcb7b1f..7ceea13c0d59 100644 --- a/vault/core_metrics.go +++ b/vault/core_metrics.go @@ -597,14 +597,14 @@ func (c *Core) inFlightReqGaugeMetric() { // configuredPoliciesGaugeCollector is used to collect gauge label values for the `vault.policy.configured.count` metric func (c *Core) configuredPoliciesGaugeCollector(ctx context.Context) ([]metricsutil.GaugeLabelValues, error) { - if c.policyStore == nil { - return []metricsutil.GaugeLabelValues{}, nil - } - c.stateLock.RLock() policyStore := c.policyStore c.stateLock.RUnlock() + if policyStore == nil { + return []metricsutil.GaugeLabelValues{}, nil + } + ctx = namespace.RootContext(ctx) namespaces := c.collectNamespaces()