Repository navigation
Proposal: Externalize or Disable Scheduled Cleanup Tasks in Keycloak (ClearExpiredEvents, UserSessions, etc.) #39374
danielzarioiu
started this conversation in
Ideas
Replies: 2 comments
|
@danielzarioiu - IMHO some advanced scheduling (with a cron syntax) might be helpful. Note that some indexes might be missing in your Keycloak instance as Keycloak sometimes skips the creation during upgrade and asks admins to create them manually. See #42892 (comment) for a longer answer. It might be worth creating an empty database and to compare that DB schema with your current schema and see if there are missing indexes. Starting with KC 25+, the necessary indexes should be in place. |
0 replies
|
I'm all for ability to have scheduled tasks run using a cron expression, not just on a time basis. Further, would be good to be able to control separately when all tasks, specific tasks, or maybe a group of task types, run. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi all,
I would like to start a discussion regarding the internal scheduled cleanup tasks in Keycloak, especially in production environments running in Kubernetes or other orchestrated environments.
📌 Background
By inspecting the source code (DefaultDatastoreProviderFactory.java), I noticed that Keycloak automatically registers and schedules internal cleanup tasks on startup:
These are scheduled to run every 15 minutes by default (configurable via scheduled.interval), but currently there is no option to disable or fine-tune their scheduling (e.g., run them at night or off-peak hours).
🧨 Problem Experienced in Production
I recently encountered a major production issue caused by an application that generated approximately 98 million offline tokens over the last 3 months due to an internal bug. As these tokens began to expire, the database was hit with a high volume of delete operations, severely impacting performance.
The cleanup task was repeatedly executing the following query:
Since the table did not have the appropriate indexes, this query caused a massive load on the database. As a result:
To resolve the issue quickly, I had to aggressively scale up the database to allow the cleanup tasks to run to completion. I also:
While the root cause was the application’s misuse of offline tokens, I believe the more significant issue is architectural. Cleanup tasks run internally within Keycloak and are not easily configurable or observable — which can be dangerous in production-grade, high-availability environments.
💡 Proposal
I propose the following improvements:
✅ Benefits
⸻
What do you think? Would this direction be valuable to the community?
Thanks!
All reactions