From 0becd555cfb4feedaf65b84936b6957b38bc4233 Mon Sep 17 00:00:00 2001 From: Hridoy Roy Date: Tue, 19 Jan 2021 14:06:50 -0800 Subject: [PATCH] Protect part of emitMetrics from panic behavior during post-seal (#10708) * vault/core_metrics.go * changelog * comments --- changelog/10708.txt | 3 +++ vault/core_metrics.go | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 changelog/10708.txt diff --git a/changelog/10708.txt b/changelog/10708.txt new file mode 100644 index 000000000..a33bfb078 --- /dev/null +++ b/changelog/10708.txt @@ -0,0 +1,3 @@ +```release-note:bug +metrics: Protect emitMetrics from panicking during post-seal +``` \ No newline at end of file diff --git a/vault/core_metrics.go b/vault/core_metrics.go index 3d24c2edd..c7d829566 100644 --- a/vault/core_metrics.go +++ b/vault/core_metrics.go @@ -259,6 +259,13 @@ func (c *Core) findKvMounts() []*kvMount { c.mountsLock.RLock() defer c.mountsLock.RUnlock() + // emitMetrics doesn't grab the statelock, so this code might run during or after the seal process. + // Therefore, we need to check if c.mounts is nil. If we do not, emitMetrics will panic if this is + // run after seal. + if c.mounts == nil { + return mounts + } + for _, entry := range c.mounts.Entries { if entry.Type == "kv" { version, ok := entry.Options["version"]