mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-29 14:41:09 +01:00
Fix race in fsm.db (#18386)
We need to take a read lock when reading any of the FSM fields. Expose a new fsm.Stats to handle a racy read and make sure we're consistently using the f.db read lock wrappers.
This commit is contained in:
parent
9e10684662
commit
af04fd08ee
@ -238,6 +238,13 @@ func (f *FSM) openDBFile(dbPath string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FSM) Stats() bolt.Stats {
|
||||||
|
f.l.RLock()
|
||||||
|
defer f.l.RUnlock()
|
||||||
|
|
||||||
|
return f.db.Stats()
|
||||||
|
}
|
||||||
|
|
||||||
func (f *FSM) Close() error {
|
func (f *FSM) Close() error {
|
||||||
f.l.RLock()
|
f.l.RLock()
|
||||||
defer f.l.RUnlock()
|
defer f.l.RUnlock()
|
||||||
|
|||||||
@ -555,7 +555,7 @@ func (b *RaftBackend) Close() error {
|
|||||||
b.l.Lock()
|
b.l.Lock()
|
||||||
defer b.l.Unlock()
|
defer b.l.Unlock()
|
||||||
|
|
||||||
if err := b.fsm.db.Close(); err != nil {
|
if err := b.fsm.Close(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,7 +612,7 @@ func (b *RaftBackend) DisableUpgradeMigration() (bool, bool) {
|
|||||||
func (b *RaftBackend) CollectMetrics(sink *metricsutil.ClusterMetricSink) {
|
func (b *RaftBackend) CollectMetrics(sink *metricsutil.ClusterMetricSink) {
|
||||||
b.l.RLock()
|
b.l.RLock()
|
||||||
logstoreStats := b.stableStore.(*raftboltdb.BoltStore).Stats()
|
logstoreStats := b.stableStore.(*raftboltdb.BoltStore).Stats()
|
||||||
fsmStats := b.fsm.db.Stats()
|
fsmStats := b.fsm.Stats()
|
||||||
stats := b.raft.Stats()
|
stats := b.raft.Stats()
|
||||||
b.l.RUnlock()
|
b.l.RUnlock()
|
||||||
b.collectMetricsWithStats(logstoreStats, sink, "logstore")
|
b.collectMetricsWithStats(logstoreStats, sink, "logstore")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user