MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / refresh_if_stale

Method refresh_if_stale

crates/openshell-server/src/auth/oidc.rs:264–276  ·  view source on GitHub ↗

Refresh keys if the TTL has elapsed. Holds the refresh mutex so concurrent callers coalesce into a single HTTP fetch. The second caller will re-check the TTL after acquiring the lock and find it fresh.

(&self)

Source from the content-addressed store, hash-verified

262 /// HTTP fetch. The second caller will re-check the TTL after acquiring
263 /// the lock and find it fresh.
264 async fn refresh_if_stale(&self) -> Result<(), String> {
265 let last = *self.last_refresh.read().await;
266 if last.elapsed() <= self.ttl {
267 return Ok(());
268 }
269 let _guard = self.refresh_mutex.lock().await;
270 // Re-check after acquiring the lock — another task may have refreshed.
271 let last = *self.last_refresh.read().await;
272 if last.elapsed() <= self.ttl {
273 return Ok(());
274 }
275 self.refresh_keys().await
276 }
277
278 /// Refresh keys unconditionally, coalescing concurrent callers.
279 async fn refresh_keys_coalesced(&self) -> Result<(), String> {

Callers 1

validate_tokenMethod · 0.80

Calls 2

refresh_keysMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected