Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

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
  • Loading branch information
pmahindrakar-oss committed May 23, 2024
1 parent 49232a2 commit 4aa2b76
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
12 changes: 8 additions & 4 deletions pkg/pkce/token_cache_keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit 4aa2b76

Please sign in to comment.