From d423462ee0c1c7ed845a734f42f80e601110a99a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 28 Oct 2026 16:01:38 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=91=20oidc:=20a=20scheduled=20key=20fe?= =?UTF-8?q?tch=20no=20longer=20delays=20the=20refetch=20for=20a=20newly=20?= =?UTF-8?q?rotated=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/iz-web/src/oidc.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/iz-web/src/oidc.rs b/crates/iz-web/src/oidc.rs index ea36a28..77bfb76 100644 --- a/crates/iz-web/src/oidc.rs +++ b/crates/iz-web/src/oidc.rs @@ -229,7 +229,7 @@ pub struct OidcClient { struct KeyCache { /// The last key set fetched, and when it was fetched. current: Option<(Instant, Arc)>, - /// When a fetch was last attempted, whether it succeeded or not. + /// When the keys were last fetched for an unknown key, or a fetch failed. Limits those fetches. last_fetch: Option, } @@ -330,9 +330,16 @@ impl OidcClient { if let Some(keys) = self.keys_without_fetch(refetch_unknown).await? { return Ok(keys); } - self.keys.lock().await.last_fetch = Some(Instant::now()); + // Only a refetch for an unknown key or a failure starts the gap. A scheduled fetch does not, so the + // first token signed by a newly rotated key is verified at once. + if refetch_unknown { + self.keys.lock().await.last_fetch = Some(Instant::now()); + } let fetched = self.fetch_keys().await; let mut cache = self.keys.lock().await; + if fetched.is_err() { + cache.last_fetch = Some(Instant::now()); + } match fetched { Ok(keys) => { cache.current = Some((Instant::now(), keys.clone())); @@ -349,7 +356,7 @@ impl OidcClient { } /// The cached key set, when no fetch is due: it is fresh, or a fetch was attempted less than - /// [`UNKNOWN_KEY_REFETCH`] ago. `None` when a fetch is due. With no cached set and a fetch attempted + /// [`UNKNOWN_KEY_REFETCH`] ago (see `last_fetch`). `None` when a fetch is due. With no cached set and a fetch attempted /// that recently, the answer is an error at once, without a network call. async fn keys_without_fetch(&self, refetch_unknown: bool) -> ImResult>> { let cache = self.keys.lock().await;