You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by sb...@apache.org on 2025/10/20 18:18:18 UTC

(tooling-trusted-releases) branch main updated: Fix a principal cache invalidation bug

This is an automated email from the ASF dual-hosted git repository.

sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git


The following commit(s) were added to refs/heads/main by this push:
     new 814903a  Fix a principal cache invalidation bug
814903a is described below

commit 814903a3ce5b796c6690ac5efea140b4344aeafe
Author: Sean B. Palmer <se...@miscoranda.com>
AuthorDate: Mon Oct 20 19:17:24 2025 +0100

    Fix a principal cache invalidation bug
---
 atr/principal.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/atr/principal.py b/atr/principal.py
index ccfad52..50c6934 100644
--- a/atr/principal.py
+++ b/atr/principal.py
@@ -210,15 +210,16 @@ class Committer:
 class Cache:
     def __init__(self, cache_for_at_most_seconds: int = 600):
         self.cache_for_at_most_seconds = cache_for_at_most_seconds
-        self.last_refreshed: int | None = None
+        self.last_refreshed: dict[str, int | None] = {}
         self.member_of: dict[str, frozenset[str]] = {}
         self.participant_of: dict[str, frozenset[str]] = {}
 
-    def outdated(self) -> bool:
-        if self.last_refreshed is None:
+    def outdated(self, asf_uid: str) -> bool:
+        last_refreshed = self.last_refreshed.get(asf_uid)
+        if last_refreshed is None:
             return True
         now = int(time.time())
-        since_last_refresh = now - self.last_refreshed
+        since_last_refresh = now - last_refreshed
         return since_last_refresh > self.cache_for_at_most_seconds
 
 
@@ -245,7 +246,7 @@ class AuthoriserASFQuart:
         return self.__cache.member_of[asf_uid], self.__cache.participant_of[asf_uid]
 
     async def cache_refresh(self, asf_uid: str, asfquart_session: session.ClientSession) -> None:
-        if not self.__cache.outdated():
+        if not self.__cache.outdated(asf_uid):
             return
         if not isinstance(asfquart_session, session.ClientSession):
             # Defense in depth runtime check, already validated by the type checker
@@ -259,7 +260,7 @@ class AuthoriserASFQuart:
         # It is the caller's responsibility to ensure this
         self.__cache.member_of[asf_uid] = committees
         self.__cache.participant_of[asf_uid] = projects
-        self.__cache.last_refreshed = int(time.time())
+        self.__cache.last_refreshed[asf_uid] = int(time.time())
 
 
 class AuthoriserLDAP:
@@ -282,7 +283,7 @@ class AuthoriserLDAP:
         return self.__cache.member_of[asf_uid], self.__cache.participant_of[asf_uid]
 
     async def cache_refresh(self, asf_uid: str) -> None:
-        if not self.__cache.outdated():
+        if not self.__cache.outdated(asf_uid):
             return
 
         if config.get().ALLOW_TESTS and (asf_uid == "test"):
@@ -291,7 +292,7 @@ class AuthoriserLDAP:
             projects = frozenset({"test"})
             self.__cache.member_of[asf_uid] = committees
             self.__cache.participant_of[asf_uid] = projects
-            self.__cache.last_refreshed = int(time.time())
+            self.__cache.last_refreshed[asf_uid] = int(time.time())
             return
 
         try:
@@ -304,7 +305,7 @@ class AuthoriserLDAP:
 
             self.__cache.member_of[asf_uid] = committees
             self.__cache.participant_of[asf_uid] = projects
-            self.__cache.last_refreshed = int(time.time())
+            self.__cache.last_refreshed[asf_uid] = int(time.time())
         except CommitterError as e:
             raise AuthenticationError(f"Failed to verify committer: {e}") from e
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org