Eason09053360 commented on code in PR #74364:
URL: https://github.com/apache/airflow/pull/74364#discussion_r4213842134


##########
airflow-core/src/airflow/models/revoked_token.py:
##########
@@ -71,9 +80,26 @@ def _maybe_cleanup_expired(cls, session: Session) -> None:
         """
         now = time.monotonic()
         cleanup_interval = conf.getint("api_auth", "jwt_expiration_time", 
fallback=3600) * 2
-        if now - cls._last_cleanup_time >= cleanup_interval:
+        if now - cls._last_cleanup_time < cleanup_interval:
+            return
+        if not cls._cleanup_lock.acquire(blocking=False):
+            return
+        try:
+            # Set before the delete so a failing database is not retried on 
every request.
             cls._last_cleanup_time = now
-            try:
-                session.execute(delete(cls).where(cls.exp < 
datetime.now(tz=timezone.utc)))
-            except Exception:
-                log.exception("Failed to clean up expired revoked tokens")
+            expired_jtis = session.scalars(

Review Comment:
   Thanks for reviewing!
   Good catch, confirmed with a forced interleaving.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to