From c220686c29f04f327de48ef43e6d515b480c9169 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 14 May 2020 13:30:21 +0100 Subject: [PATCH] Fix token bug --- auth/service/service.go | 2 +- service.go | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/auth/service/service.go b/auth/service/service.go index ecb605f4..482b488f 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -315,9 +315,9 @@ func NewAuth(opts ...auth.Option) auth.Auth { ruleTimer := time.NewTicker(time.Second * 30) for { + <-ruleTimer.C time.Sleep(jitter.Do(time.Second * 5)) service.loadRules() - <-ruleTimer.C } }() diff --git a/service.go b/service.go index b3ebc1ae..f37dc83b 100644 --- a/service.go +++ b/service.go @@ -252,7 +252,7 @@ func (s *service) generateAccount() error { // generate the first token token, err := s.Options().Auth.Token( auth.WithCredentials(accID, accSecret), - auth.WithExpiry(time.Minute*15), + auth.WithExpiry(time.Minute*10), ) if err != nil { return err @@ -272,14 +272,15 @@ func (s *service) generateAccount() error { <-timer.C // don't refresh the token if it's not close to expiring - if token.Expiry.Unix() > time.Now().Add(time.Minute).Unix() { + tok := s.Options().Auth.Options().Token + if tok.Expiry.Unix() > time.Now().Add(time.Minute).Unix() { continue } // generate the first token - token, err := s.Options().Auth.Token( + tok, err := s.Options().Auth.Token( auth.WithCredentials(accID, accSecret), - auth.WithExpiry(time.Minute*15), + auth.WithExpiry(time.Minute*10), ) if err != nil { logger.Warnf("[Auth] Error refreshing token: %v", err) @@ -287,7 +288,7 @@ func (s *service) generateAccount() error { } // set the token - s.Options().Auth.Init(auth.ClientToken(token)) + s.Options().Auth.Init(auth.ClientToken(tok)) } }()