From 20025432454eab3c637452adf3c66042909f029c Mon Sep 17 00:00:00 2001 From: Chris Hoffman Date: Mon, 11 Sep 2017 11:17:22 -0400 Subject: [PATCH] Switching atomic vars to int32 to address panic on some architectures (#3314) --- vault/expiration.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/vault/expiration.go b/vault/expiration.go index d7b00af39..41a697291 100644 --- a/vault/expiration.go +++ b/vault/expiration.go @@ -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 @@ -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{ @@ -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 @@ -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") @@ -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: @@ -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")