Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add await busy loop for SimpleKdcLdapServer initialization #39221

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,43 @@ public Boolean run() throws Exception {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
init();
if (ESTestCase.awaitBusy(() -> init()) == false) {
throw new IllegalStateException("could not initialize SimpleKdcLdapServer");
}
return null;
}
});
logger.info("SimpleKdcLdapServer started.");
}

@SuppressForbidden(reason = "Uses Apache Kdc which requires usage of java.io.File in order to create a SimpleKdcServer")
private void init() throws Exception {
// start ldap server
createLdapServiceAndStart();
// create ldap backend conf
createLdapBackendConf();
// Kdc Server
simpleKdc = new SimpleKdcServer(this.workDir.toFile(), new KrbConfig());
prepareKdcServerAndStart();
private boolean init() {
boolean initialized = false;
try {
// start ldap server
createLdapServiceAndStart();
// create ldap backend conf
createLdapBackendConf();
// Kdc Server
simpleKdc = new SimpleKdcServer(this.workDir.toFile(), new KrbConfig());
prepareKdcServerAndStart();
initialized = true;
} catch (Exception e) {
if (simpleKdc != null) {
try {
simpleKdc.stop();
} catch (KrbException krbException) {
logger.debug("error occurred while cleaning up after init failure for SimpleKdcLdapServer");
}
}
if (ldapServer != null) {
ldapServer.shutDown(true);
}
ldapPort = 0;
kdcPort = 0;
initialized = false;
}
return initialized;
}

private void createLdapServiceAndStart() throws Exception {
Expand Down Expand Up @@ -229,12 +250,14 @@ private static int getServerPort(String transport) {
if (transport != null && transport.trim().equalsIgnoreCase("TCP")) {
try (ServerSocket serverSocket = ServerSocketFactory.getDefault().createServerSocket(0, 1,
InetAddress.getByName("127.0.0.1"))) {
serverSocket.setReuseAddress(true);
return serverSocket.getLocalPort();
} catch (Exception ex) {
throw new RuntimeException("Failed to get a TCP server socket point");
}
} else if (transport != null && transport.trim().equalsIgnoreCase("UDP")) {
try (DatagramSocket socket = new DatagramSocket(0, InetAddress.getByName("127.0.0.1"))) {
socket.setReuseAddress(true);
return socket.getLocalPort();
} catch (Exception ex) {
throw new RuntimeException("Failed to get a UDP server socket point");
Expand Down