Skip to content

Commit

Permalink
Stop copying sync.Maps, which is forbidden. (#24027)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncabatoff authored Nov 6, 2023
1 parent b19562d commit 7ec3867
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog/24027.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
expiration: Fix fatal error "concurrent map iteration and map write" when collecting metrics from leases.
```
6 changes: 3 additions & 3 deletions vault/expiration.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ func (m *ExpirationManager) Stop() error {
// for the next ExpirationManager to handle them.
newStrategy := ExpireLeaseStrategy(expireNoop)
m.expireFunc.Store(&newStrategy)
oldPending := m.pending
oldPending := &m.pending
m.pending, m.nonexpiring, m.irrevocable = sync.Map{}, sync.Map{}, sync.Map{}
m.leaseCount = 0
m.uniquePolicies = make(map[string][]string)
Expand Down Expand Up @@ -2485,7 +2485,7 @@ func (m *ExpirationManager) WalkTokens(walkFn ExpirationWalkFunction) error {
}

m.pendingLock.RLock()
toWalk := []sync.Map{m.pending, m.nonexpiring}
toWalk := []*sync.Map{&m.pending, &m.nonexpiring}
m.pendingLock.RUnlock()

for _, m := range toWalk {
Expand Down Expand Up @@ -2514,7 +2514,7 @@ func (m *ExpirationManager) walkLeases(walkFn leaseWalkFunction) error {
}

m.pendingLock.RLock()
toWalk := []sync.Map{m.pending, m.nonexpiring}
toWalk := []*sync.Map{&m.pending, &m.nonexpiring}
m.pendingLock.RUnlock()

for _, m := range toWalk {
Expand Down

0 comments on commit 7ec3867

Please sign in to comment.