Repository navigation
Description
Area
testsuite
Describe the bug
MySQLDistTest.testSuccessful and MySQLDistTest.testWarningForTooShortLifetime intermittently fail with IllegalThreadStateException: process hasn't exited.
Root cause has two parts:
-
Startup timeout too short for MySQL migrations. The
startTimeoutinKeycloakRunnerdefaults to 120 seconds, but MySQL Liquibase migrations can exceed 2 minutes on slow CI runners (observed: ~127 seconds). When the timeout is exceeded,waitFor()throws aRuntimeException, and thefinallyblock inKeycloakRunner.run()callsstop()on the still-running process. -
RawKeycloakDistribution.stop()doesn't handle graceful shutdown timeout.stop()callskeycloak.destroy()followed bykeycloak.waitFor(10, SECONDS). IfwaitFor()returnsfalse(process didn't stop in time), the return value is silently ignored and the code falls through tokeycloak.exitValue(), which throwsIllegalThreadStateExceptionbecause the process is still alive. The force-kill path (destroyForcibly()) only runs on exceptions fromwaitFor(), not on timeout.
Version
nightly (observed on 2026-09-03)
Regression
- The issue is a regression
Expected behavior
- MySQL migration tests should have enough startup time to complete Liquibase migrations on slow CI runners.
- If a Keycloak process doesn't stop gracefully within the timeout,
stop()should force-kill it and report a clear error, not throwIllegalThreadStateException.
Actual behavior
java.lang.IllegalThreadStateException: process hasn't exited
at java.base/java.lang.ProcessImpl.exitValue(ProcessImpl.java:450)
at org.keycloak.it.utils.RawKeycloakDistribution.stop(RawKeycloakDistribution.java:221)
at org.keycloak.it.junit5.extension.KeycloakRunner.run(KeycloakRunner.java:87)
at org.keycloak.it.junit5.extension.CLITestExtension.beforeEach(CLITestExtension.java:107)
Both testSuccessful (186.2s) and testWarningForTooShortLifetime (160.5s) fail with this error. The failure cascades: after the first test leaks a process, subsequent tests also fail in their beforeEach when trying to stop the leaked process.
How to Reproduce?
The failure is timing-dependent and occurs on slow CI runners where MySQL Liquibase migrations take longer than 120 seconds. Example:
https://github.com/keycloak/keycloak/actions/runs/33744013985/job/100626664256?pr=52128
Anything else?
Fix (two parts):
-
Increase
startTimeoutdefault from 120s to 300s inKeycloakRunnerto accommodate slow MySQL migrations. -
In
RawKeycloakDistribution.stop(), check the return value ofwaitFor(). When graceful shutdown times out, throw aRuntimeExceptionso the existingcatchblock force-kills the process, captures a thread dump, and reports a clear error.
Activity
Extend startup time for MySQL migrations and force cleanup after failure
13 remaining items
Extend startup time for MySQL migrations and force cleanup after failure