Skip to content

Commit

Permalink
Lock the locker in the wait to adher to cond.Wait() semantics
Browse files Browse the repository at this point in the history
Signed-off-by: pmahindrakar-oss <[email protected]>
  • Loading branch information
pmahindrakar-oss committed May 23, 2024
1 parent e30846e commit 3fda00e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions flyteidl/clients/go/admin/cache/token_cache_inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func (t *TokenCacheInMemoryProvider) GetToken() (*oauth2.Token, error) {
if tkn == nil {
return nil, fmt.Errorf("cannot find token in cache")
}

return tkn.(*oauth2.Token), nil
}

Expand All @@ -46,8 +45,12 @@ func (t *TokenCacheInMemoryProvider) Unlock() {
}

// CondWait waits for the condition to be true.
// It also locks the Locker in the condition variable as the semantics of Wait is that it unlocks the Locker after adding
// the consumer to the waitlist and before blocking on notification.
func (t *TokenCacheInMemoryProvider) CondWait() {
t.cond.L.Lock()
t.cond.Wait()
t.cond.L.Unlock()
}

// CondBroadcast signals the condition.
Expand All @@ -56,10 +59,9 @@ func (t *TokenCacheInMemoryProvider) CondBroadcast() {
}

func NewTokenCacheInMemoryProvider() *TokenCacheInMemoryProvider {
condMutex := &sync.Mutex{}
return &TokenCacheInMemoryProvider{
mu: condMutex,
mu: &sync.Mutex{},
token: atomic.Value{},
cond: sync.NewCond(condMutex),
cond: sync.NewCond(&sync.Mutex{}),
}
}

0 comments on commit 3fda00e

Please sign in to comment.