You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Configurable transaction timeouts with categories #26889
Keycloak currently sets the transaction timeout to 300 seconds. It is set at a large value to prevent migration of the database timing out.
There is no supported way to configure the transaction timeout, but it can be configured through quarkus.properties with quarkus.transaction-manager.default-transaction-timeout.
However, for Keycloak it makes little sense to have a single transaction timeout for everything and it should be possible to set different timeouts for:
With #19453#46671 Migration/startup tasks are covered by a single configurable timeout.
import at startup along with kc.sh import are effectively covered by the changes proposed by #46671 - export may be applicable as well.
With migration and import / export covered by the default of 30 minutes it does not seem like any other operation should require anywhere near a default of 5 minutes.
I would think ldap full sync might need a longer timeout. I would like to give it some more thought as the list above might be incomplete.
Btw, despite my previous comment on another ticket, maybe export and import should not have a timeout. Who would want to run an export for hours, and then figure out they set the wrong timeout?
I would think ldap full sync might need a longer timeout.
This would fall under a category of background / timed tasks correct?
maybe export and import should not have a timeout. Who would want to run an export for hours, and then figure out they set the wrong timeout?
I believe the same concern has been expressed about migration - especially because I believe we have seen instances where things were non-recoverable after erroring out.
@ahus1@shawkins are you suggesting use Integer.MAX_VALUE as timeout for these tasks? I assume the CLI option transaction-migration-timeout could be removed, which would be great, and the lock timeout would be "infinity" too.
I personally don't like it, but should I do it to keep things simpler?
We need to also consider the operator and kube in general - #36308 was resolved as a doc change, but 1 hour was previously proposed as the startup default. As it stands now out-of-the-box the operator uses a 10 minute startup timeout - if a migration exceeds that, kube will kill the pod.
At least from the analysis we did at that time, the initialization / migration logic effectively blocks the http endpoints from becoming available. This means we can't easily do anything other than having a long startup probe timeout - although we did talk about things like running migration as a job instead of via server start, and not blocking startup for migration and instead have an internal notion of readiness.
cc @keycloak/cloud-native
@ahus1@shawkins are you suggesting use Integer.MAX_VALUE as timeout for these tasks? I assume the CLI option transaction-migration-timeout could be removed, which would be great, and the lock timeout would be "infinity" too. I personally don't like it, but should I do it to keep things simpler?
I don't really like unlimited either - and I'm also not sure what that would translate to for a meaningful kube startup probe timeout. I tried searching support tickets and couldn't really find anything about what users have increased the value to in the past.
Ideally the timeout would be progressive - as long as we are making progress, it should be extended, but that doesn't seem to be supported by the transaction manager.
Why not invoke the bootstrap() method (where migration happens) in a different thread?
The method void onStartupEvent(@Observes StartupEvent event) will complete immediately, and Quarkus will open the REST endpoint -> /health/live returns 200
A custom readiness check will return DOWN until the bootstrap() toggles a boolean (switches from DOWN to UP)
A custom request filter returns 503 to all requests (except /health, but it is not clear to me if /health can be filtered) until bootstrap() toggles a boolean (disabling the filter).
AFAIK, Kubernetes never kills a Pod with live=true and ready=false, and Keycloak will have all the time for migration.
EDIT: I actually forgot that Liquibase migration happens during the KeycloakSessionFactory initialization. So the suggestion above may not work...
EDIT2: ...or move the init() to the same thread handling the bootstrap().
@pruivo what you are describing is what I was trying to convey by not blocking and having an internal notion of readiness - that's a significantly larger change than just modifying the startup probe timeout.
Activity
shawkins commentedon Feb 27, 2026
With #19453 #46671 Migration/startup tasks are covered by a single configurable timeout.
import at startup along with kc.sh import are effectively covered by the changes proposed by #46671 - export may be applicable as well.
With migration and import / export covered by the default of 30 minutes it does not seem like any other operation should require anywhere near a default of 5 minutes.
cc @pruivo @ahus1
ahus1 commentedon Feb 27, 2026
I would think ldap full sync might need a longer timeout. I would like to give it some more thought as the list above might be incomplete.
Btw, despite my previous comment on another ticket, maybe export and import should not have a timeout. Who would want to run an export for hours, and then figure out they set the wrong timeout?
shawkins commentedon Feb 27, 2026
This would fall under a category of background / timed tasks correct?
I believe the same concern has been expressed about migration - especially because I believe we have seen instances where things were non-recoverable after erroring out.
pruivo commentedon Mar 2, 2026
@ahus1 @shawkins are you suggesting use
Integer.MAX_VALUEas timeout for these tasks? I assume the CLI optiontransaction-migration-timeoutcould be removed, which would be great, and the lock timeout would be "infinity" too.I personally don't like it, but should I do it to keep things simpler?
shawkins commentedon Mar 2, 2026
We need to also consider the operator and kube in general - #36308 was resolved as a doc change, but 1 hour was previously proposed as the startup default. As it stands now out-of-the-box the operator uses a 10 minute startup timeout - if a migration exceeds that, kube will kill the pod.
At least from the analysis we did at that time, the initialization / migration logic effectively blocks the http endpoints from becoming available. This means we can't easily do anything other than having a long startup probe timeout - although we did talk about things like running migration as a job instead of via server start, and not blocking startup for migration and instead have an internal notion of readiness.
cc @keycloak/cloud-native
I don't really like unlimited either - and I'm also not sure what that would translate to for a meaningful kube startup probe timeout. I tried searching support tickets and couldn't really find anything about what users have increased the value to in the past.
Ideally the timeout would be progressive - as long as we are making progress, it should be extended, but that doesn't seem to be supported by the transaction manager.
pruivo commentedon Mar 2, 2026
Why not invoke the
bootstrap()method (where migration happens) in a different thread?void onStartupEvent(@Observes StartupEvent event)will complete immediately, and Quarkus will open the REST endpoint -> /health/live returns 200DOWNuntil thebootstrap()toggles a boolean (switches fromDOWNtoUP)/health, but it is not clear to me if/healthcan be filtered) untilbootstrap()toggles a boolean (disabling the filter).AFAIK, Kubernetes never kills a Pod with live=true and ready=false, and Keycloak will have all the time for migration.
EDIT: I actually forgot that Liquibase migration happens during the
KeycloakSessionFactoryinitialization. So the suggestion above may not work...EDIT2: ...or move the
init()to the same thread handling thebootstrap().shawkins commentedon Mar 2, 2026
@pruivo what you are describing is what I was trying to convey by not blocking and having an internal notion of readiness - that's a significantly larger change than just modifying the startup probe timeout.
ahus1 commentedon Mar 3, 2026
+1 for what @pruivo is suggesting or something similar, as that is probably the only way to solve the migration on Kubernetes in a good way.
This is issue #41002 for this, let's continue there.