Skip to content

Commit a1d4b46

Browse files
committed
Refactor key refresh to minimize lock duration
1 parent 6c2be2c commit a1d4b46

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

enterprise/wsproxy/keycache.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,14 @@ func checkKey(key codersdk.CryptoKey, sequence int32, now time.Time) (codersdk.C
148148

149149
// refresh fetches the keys from the control plane and updates the cache.
150150
func (k *CryptoKeyCache) refresh() {
151+
now := k.Clock.Now("CryptoKeyCache", "refresh")
152+
k.mu.Lock()
153+
151154
if k.closed {
155+
k.mu.Unlock()
152156
return
153157
}
154158

155-
now := k.Clock.Now("CryptoKeyCache", "refresh")
156-
157-
k.mu.Lock()
158-
159159
// If something's already fetching, we don't need to do anything.
160160
if k.fetching {
161161
k.mu.Unlock()

0 commit comments

Comments
 (0)