task: ensuring that keycloaksessions are closed (#27682)
closes: #27681 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
parent
161936aa4c
commit
a3be85b2cd
3 changed files with 16 additions and 15 deletions
|
@ -22,6 +22,7 @@ import static org.keycloak.common.util.Resteasy.clearContextData;
|
|||
import jakarta.ws.rs.container.CompletionCallback;
|
||||
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;
|
||||
import org.jboss.resteasy.reactive.server.spi.ServerRestHandler;
|
||||
import org.keycloak.common.util.Resteasy;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.quarkus.runtime.transaction.TransactionalSessionHandler;
|
||||
|
||||
|
@ -39,13 +40,20 @@ public final class CreateSessionHandler implements ServerRestHandler, Transactio
|
|||
if (currentSession == null) {
|
||||
// this handler might be invoked multiple times when resolving sub-resources
|
||||
// make sure the session is created once
|
||||
routingContext.put(KeycloakSession.class.getName(), create());
|
||||
KeycloakSession session = create();
|
||||
routingContext.put(KeycloakSession.class.getName(), session);
|
||||
context.registerCompletionCallback(this);
|
||||
Resteasy.pushContext(KeycloakSession.class, session);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(Throwable throwable) {
|
||||
try {
|
||||
close(Resteasy.getContextData(KeycloakSession.class));
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
clearContextData();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,8 +78,7 @@ public class FipsDistTest {
|
|||
dist.copyOrReplaceFileFromClasspath("/server.keystore", Path.of("conf", "server.keystore"));
|
||||
CLIResult cliResult = dist.run("start", "--fips-mode=strict");
|
||||
dist.assertStopped();
|
||||
// after https://issues.redhat.com/browse/JBTM-3830 reenable this check
|
||||
//cliResult.assertMessage("ERROR: java.lang.IllegalArgumentException: malformed sequence");
|
||||
cliResult.assertMessage("ERROR: java.lang.IllegalArgumentException: malformed sequence");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -127,8 +126,7 @@ public class FipsDistTest {
|
|||
dist.copyOrReplaceFileFromClasspath("/server.keystore.pkcs12", Path.of("conf", "server.keystore"));
|
||||
CLIResult cliResult = dist.run("start", "--fips-mode=strict", "--https-key-store-password=passwordpassword");
|
||||
dist.assertStopped();
|
||||
// after https://issues.redhat.com/browse/JBTM-3830 reenable this check
|
||||
//cliResult.assertMessage("ERROR: java.lang.IllegalArgumentException: malformed sequence");
|
||||
cliResult.assertMessage("ERROR: java.lang.IllegalArgumentException: malformed sequence");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -79,10 +79,6 @@ import static org.keycloak.quarkus.runtime.Environment.isWindows;
|
|||
|
||||
public final class RawKeycloakDistribution implements KeycloakDistribution {
|
||||
|
||||
// TODO: reconsider the hardcoded timeout once https://issues.redhat.com/browse/JBTM-3830 is pulled into Keycloak
|
||||
// ensures that the total wait time (two minutes for readiness + 200 seconds) is longer than the transaction timeout of 5 minutes
|
||||
private static final int LONG_SHUTDOWN_WAIT = 200;
|
||||
|
||||
private static final int DEFAULT_SHUTDOWN_TIMEOUT_SECONDS = 10;
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(RawKeycloakDistribution.class);
|
||||
|
@ -166,7 +162,7 @@ public final class RawKeycloakDistribution implements KeycloakDistribution {
|
|||
destroyDescendantsOnWindows(keycloak, false);
|
||||
|
||||
keycloak.destroy();
|
||||
keycloak.waitFor(LONG_SHUTDOWN_WAIT, TimeUnit.SECONDS);
|
||||
keycloak.waitFor(DEFAULT_SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
|
||||
exitCode = keycloak.exitValue();
|
||||
} catch (Exception cause) {
|
||||
destroyDescendantsOnWindows(keycloak, true);
|
||||
|
@ -266,7 +262,7 @@ public final class RawKeycloakDistribution implements KeycloakDistribution {
|
|||
public void assertStopped() {
|
||||
try {
|
||||
if (keycloak != null) {
|
||||
keycloak.onExit().get(LONG_SHUTDOWN_WAIT, TimeUnit.SECONDS);
|
||||
keycloak.onExit().get(DEFAULT_SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
|
@ -276,7 +272,7 @@ public final class RawKeycloakDistribution implements KeycloakDistribution {
|
|||
} catch (TimeoutException e) {
|
||||
LOG.warn("Process did not exit as expected, will attempt a thread dump");
|
||||
threadDump();
|
||||
LOG.warn("TODO: this should be a hard error / re-diagnosed after https://issues.redhat.com/browse/JBTM-3830 is pulled into Keycloak");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -297,9 +293,8 @@ public final class RawKeycloakDistribution implements KeycloakDistribution {
|
|||
while (true) {
|
||||
if (System.currentTimeMillis() - startTime > getStartTimeout()) {
|
||||
threadDump();
|
||||
LOG.warn("Timeout [" + getStartTimeout() + "] while waiting for Quarkus server", ex);
|
||||
LOG.warn("TODO: this should be a hard error / re-diagnosed after https://issues.redhat.com/browse/JBTM-3830 is pulled into Keycloak");
|
||||
return;
|
||||
throw new IllegalStateException(
|
||||
"Timeout [" + getStartTimeout() + "] while waiting for Quarkus server", ex);
|
||||
}
|
||||
|
||||
if (!keycloak.isAlive()) {
|
||||
|
|
Loading…
Reference in a new issue