MCPcopy Index your code
hub / github.com/coder/coder / refresh

Method refresh

coderd/cryptokeys/cache.go:303–343  ·  view source on GitHub ↗

refresh fetches the keys and updates the cache.

()

Source from the content-addressed store, hash-verified

301
302// refresh fetches the keys and updates the cache.
303func (c *cache) refresh() {
304 now := c.clock.Now("CryptoKeyCache", "refresh")
305 c.mu.Lock()
306
307 if c.closed {
308 c.mu.Unlock()
309 return
310 }
311
312 // If something's already fetching, we don't need to do anything.
313 if c.fetching {
314 c.mu.Unlock()
315 return
316 }
317
318 // There's a window we must account for where the timer fires while a fetch
319 // is ongoing but prior to the timer getting reset. In this case we want to
320 // avoid double fetching.
321 if now.Sub(c.lastFetch) < refreshInterval {
322 c.mu.Unlock()
323 return
324 }
325
326 c.fetching = true
327
328 c.mu.Unlock()
329 keys, err := c.cryptoKeys(c.ctx)
330 if err != nil {
331 c.logger.Error(c.ctx, "fetch crypto keys", slog.Error(err))
332 return
333 }
334
335 c.mu.Lock()
336 defer c.mu.Unlock()
337
338 c.lastFetch = c.clock.Now()
339 c.refresher.Reset(refreshInterval)
340 c.keys = keys
341 c.fetching = false
342 c.cond.Broadcast()
343}
344
345// cryptoKeys queries the control plane for the crypto keys.
346// Outside of initialization, this should only be called by fetch.

Callers 2

handleRefreshFunction · 0.45

Calls 5

cryptoKeysMethod · 0.95
ResetMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected