backport of commit 7ec3867eea2ad3c405f15f9ab5447618685739cf (#24031)

Co-authored-by: Nick Cabatoff <ncabatoff@hashicorp.com>
This commit is contained in:
hc-github-team-secure-vault-core 2023-11-06 10:48:43 -05:00 committed by GitHub
parent 2bf61de125
commit 1014555b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

3
changelog/24027.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
expiration: Fix fatal error "concurrent map iteration and map write" when collecting metrics from leases.
```

View File

@ -884,7 +884,7 @@ func (m *ExpirationManager) Stop() error {
// for the next ExpirationManager to handle them. // for the next ExpirationManager to handle them.
newStrategy := ExpireLeaseStrategy(expireNoop) newStrategy := ExpireLeaseStrategy(expireNoop)
m.expireFunc.Store(&newStrategy) m.expireFunc.Store(&newStrategy)
oldPending := m.pending oldPending := &m.pending
m.pending, m.nonexpiring, m.irrevocable = sync.Map{}, sync.Map{}, sync.Map{} m.pending, m.nonexpiring, m.irrevocable = sync.Map{}, sync.Map{}, sync.Map{}
m.leaseCount = 0 m.leaseCount = 0
m.uniquePolicies = make(map[string][]string) m.uniquePolicies = make(map[string][]string)
@ -2490,7 +2490,7 @@ func (m *ExpirationManager) WalkTokens(walkFn ExpirationWalkFunction) error {
} }
m.pendingLock.RLock() m.pendingLock.RLock()
toWalk := []sync.Map{m.pending, m.nonexpiring} toWalk := []*sync.Map{&m.pending, &m.nonexpiring}
m.pendingLock.RUnlock() m.pendingLock.RUnlock()
for _, m := range toWalk { for _, m := range toWalk {
@ -2519,7 +2519,7 @@ func (m *ExpirationManager) walkLeases(walkFn leaseWalkFunction) error {
} }
m.pendingLock.RLock() m.pendingLock.RLock()
toWalk := []sync.Map{m.pending, m.nonexpiring} toWalk := []*sync.Map{&m.pending, &m.nonexpiring}
m.pendingLock.RUnlock() m.pendingLock.RUnlock()
for _, m := range toWalk { for _, m := range toWalk {