Skip to content

Commit

Permalink
Switching atomic vars to int32 to address panic on some architectures (
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishoffman authored Sep 11, 2017
1 parent e22d707 commit 10b20e5
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions vault/expiration.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ type ExpirationManager struct {
pending map[string]*time.Timer
pendingLock sync.RWMutex

tidyLock int64
tidyLock int32

// A set of locks to handle restoration
restoreMode int64
restoreMode int32
restoreModeLock sync.RWMutex
restoreRequestLock sync.RWMutex
restoreLocks []*locksutil.LockEntry
Expand All @@ -76,7 +75,6 @@ type ExpirationManager struct {
func NewExpirationManager(router *Router, view *BarrierView, ts *TokenStore, logger log.Logger) *ExpirationManager {
if logger == nil {
logger = log.New("expiration_manager")

}

exp := &ExpirationManager{
Expand Down Expand Up @@ -150,7 +148,7 @@ func (m *ExpirationManager) unlockLease(leaseID string) {

// inRestoreMode returns if we are currently in restore mode
func (m *ExpirationManager) inRestoreMode() bool {
return atomic.LoadInt64(&m.restoreMode) == 1
return atomic.LoadInt32(&m.restoreMode) == 1
}

// Tidy cleans up the dangling storage entries for leases. It scans the storage
Expand All @@ -166,12 +164,12 @@ func (m *ExpirationManager) Tidy() error {

var tidyErrors *multierror.Error

if !atomic.CompareAndSwapInt64(&m.tidyLock, 0, 1) {
if !atomic.CompareAndSwapInt32(&m.tidyLock, 0, 1) {
m.logger.Warn("expiration: tidy operation on leases is already in progress")
return fmt.Errorf("tidy operation on leases is already in progress")
}

defer atomic.CompareAndSwapInt64(&m.tidyLock, 1, 0)
defer atomic.CompareAndSwapInt32(&m.tidyLock, 1, 0)

m.logger.Info("expiration: beginning tidy operation on leases")
defer m.logger.Info("expiration: finished tidy operation on leases")
Expand Down Expand Up @@ -276,7 +274,7 @@ func (m *ExpirationManager) Restore(errorFunc func(), loadDelay time.Duration) (
// if restore mode finished successfully, restore mode was already
// disabled with the lock. In an error state, this will allow the
// Stop() function to shut everything down.
atomic.StoreInt64(&m.restoreMode, 0)
atomic.StoreInt32(&m.restoreMode, 0)

switch {
case retErr == nil:
Expand Down Expand Up @@ -391,7 +389,7 @@ func (m *ExpirationManager) Restore(errorFunc func(), loadDelay time.Duration) (
m.restoreModeLock.Lock()
m.restoreLoaded = sync.Map{}
m.restoreLocks = nil
atomic.StoreInt64(&m.restoreMode, 0)
atomic.StoreInt32(&m.restoreMode, 0)
m.restoreModeLock.Unlock()

m.logger.Info("expiration: lease restore complete")
Expand Down

0 comments on commit 10b20e5

Please sign in to comment.