From 4aa2b76eff259199bb1d65baf1c8432ec024e90b Mon Sep 17 00:00:00 2001 From: pmahindrakar-oss Date: Thu, 23 May 2024 00:22:29 -0700 Subject: [PATCH] Lock the locker in the wait to adher to cond.Wait() semantics --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- pkg/pkce/token_cache_keyring.go | 12 ++++++++---- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 7e2d002a..b8a532ed 100644 --- a/go.mod +++ b/go.mod @@ -178,8 +178,8 @@ require ( ) replace ( - github.com/flyteorg/flyte/flyteidl => github.com/flyteorg/flyte/flyteidl v1.12.1-0.20240522054314-d3081ca4ccd7 - github.com/flyteorg/flyte/flyteplugins => github.com/flyteorg/flyte/flyteplugins v1.12.1-0.20240522054314-d3081ca4ccd7 - github.com/flyteorg/flyte/flytepropeller => github.com/flyteorg/flyte/flytepropeller v1.12.1-0.20240522054314-d3081ca4ccd7 - github.com/flyteorg/flyte/flytestdlib => github.com/flyteorg/flyte/flytestdlib v1.12.1-0.20240522054314-d3081ca4ccd7 + github.com/flyteorg/flyte/flyteidl => github.com/flyteorg/flyte/flyteidl v1.12.1-0.20240523071823-0c14c3134146 + github.com/flyteorg/flyte/flyteplugins => github.com/flyteorg/flyte/flyteplugins v1.12.1-0.20240523071823-0c14c3134146 + github.com/flyteorg/flyte/flytepropeller => github.com/flyteorg/flyte/flytepropeller v1.12.1-0.20240523071823-0c14c3134146 + github.com/flyteorg/flyte/flytestdlib => github.com/flyteorg/flyte/flytestdlib v1.12.1-0.20240523071823-0c14c3134146 ) diff --git a/go.sum b/go.sum index 6104b8a1..d56394a5 100644 --- a/go.sum +++ b/go.sum @@ -352,14 +352,14 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/flyteorg/flyte/flyteidl v1.12.1-0.20240522054314-d3081ca4ccd7 h1:EZzn0CvXDTw1HO4FxVyFYlDOhqgYzbt1QWdAmKiuDoc= -github.com/flyteorg/flyte/flyteidl v1.12.1-0.20240522054314-d3081ca4ccd7/go.mod h1:ki0nYf4mHM5VyaXY3lpndDSRqvUvmqlnyLENVu06dSQ= -github.com/flyteorg/flyte/flyteplugins v1.12.1-0.20240522054314-d3081ca4ccd7 h1:BhINwrd8+H4mFfuy8xI3Vmf7rMXTXhf5i6jQq1MnPi4= -github.com/flyteorg/flyte/flyteplugins v1.12.1-0.20240522054314-d3081ca4ccd7/go.mod h1:Zr3nUQN5FREE0Qzg0MteW2H46YFKYJMiu6F8oPmU46g= -github.com/flyteorg/flyte/flytepropeller v1.12.1-0.20240522054314-d3081ca4ccd7 h1:yy9V0IO9CA+K/UyocLQzLvdhRbaHndMHbx6ZYHtPz0c= -github.com/flyteorg/flyte/flytepropeller v1.12.1-0.20240522054314-d3081ca4ccd7/go.mod h1:Pqr+Usd2CPO/nynhy1O2zEzyLZerVflH80N/k9H89Ag= -github.com/flyteorg/flyte/flytestdlib v1.12.1-0.20240522054314-d3081ca4ccd7 h1:a0evKvbtn8C8+03Bg/ozXyWOIqdbmoDc3LVWjLSXF04= -github.com/flyteorg/flyte/flytestdlib v1.12.1-0.20240522054314-d3081ca4ccd7/go.mod h1:l1mK3nAptXTkVBKtrYT3v0ezLJj6BtgfBs/5ywPrO8o= +github.com/flyteorg/flyte/flyteidl v1.12.1-0.20240523071823-0c14c3134146 h1:g1DOLB6yAWKEKZ3IGUFSa//6Iam/9LhW25Kk1WfvA/A= +github.com/flyteorg/flyte/flyteidl v1.12.1-0.20240523071823-0c14c3134146/go.mod h1:ki0nYf4mHM5VyaXY3lpndDSRqvUvmqlnyLENVu06dSQ= +github.com/flyteorg/flyte/flyteplugins v1.12.1-0.20240523071823-0c14c3134146 h1:IFbJtEsNQIzyXXttW5Vf/MLtHBtgXFKM2AFeZq5QvlE= +github.com/flyteorg/flyte/flyteplugins v1.12.1-0.20240523071823-0c14c3134146/go.mod h1:Zr3nUQN5FREE0Qzg0MteW2H46YFKYJMiu6F8oPmU46g= +github.com/flyteorg/flyte/flytepropeller v1.12.1-0.20240523071823-0c14c3134146 h1:9BSCucnTkSgmKHrjLl++i9sxcxQhqUlMiNu1TUQHTdc= +github.com/flyteorg/flyte/flytepropeller v1.12.1-0.20240523071823-0c14c3134146/go.mod h1:Pqr+Usd2CPO/nynhy1O2zEzyLZerVflH80N/k9H89Ag= +github.com/flyteorg/flyte/flytestdlib v1.12.1-0.20240523071823-0c14c3134146 h1:z5ZIp4xDO3UNbRJu2sE/y098T4J7IH5sHTroqBswaDI= +github.com/flyteorg/flyte/flytestdlib v1.12.1-0.20240523071823-0c14c3134146/go.mod h1:l1mK3nAptXTkVBKtrYT3v0ezLJj6BtgfBs/5ywPrO8o= github.com/flyteorg/stow v0.3.10 h1:uEe+tI+CGKn21H93uXp9z05hqynEki2BO9KkW/GweY8= github.com/flyteorg/stow v0.3.10/go.mod h1:fArjMpsYJNWkp/hyDKKdbcv07gxbuLmKFcb7YT1aSOM= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= diff --git a/pkg/pkce/token_cache_keyring.go b/pkg/pkce/token_cache_keyring.go index 43739aa2..ffb9152f 100644 --- a/pkg/pkce/token_cache_keyring.go +++ b/pkg/pkce/token_cache_keyring.go @@ -51,9 +51,14 @@ func (t *TokenCacheKeyringProvider) TryLock() bool { return t.mu.TryLock() } -// CondWait waits for the condition to be true. +// CondWait adds the current go routine to the condition waitlist and waits for another go routine to notify using CondBroadcast +// The current usage is that one who was able to acquire the lock using TryLock is the one who gets a valid token and notifies all the waitlist requesters so that they can use the new valid token. +// 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 *TokenCacheKeyringProvider) CondWait() { + t.cond.L.Lock() t.cond.Wait() + t.cond.L.Unlock() } // CondBroadcast broadcasts the condition. @@ -100,10 +105,9 @@ func (t *TokenCacheKeyringProvider) GetToken() (*oauth2.Token, error) { } func NewTokenCacheKeyringProvider(serviceName, serviceUser string) *TokenCacheKeyringProvider { - condMutex := &sync.Mutex{} return &TokenCacheKeyringProvider{ - mu: condMutex, - cond: sync.NewCond(condMutex), + mu: &sync.Mutex{}, + cond: sync.NewCond(&sync.Mutex{}), ServiceName: serviceName, ServiceUser: serviceUser, }