Retry server startup
The server startup hangs intermittently in windows without a specific
reason. The fix is to retry server startup for 3 attempts and fail if
it still doesn't start.
@@ -69,6 +69,8 @@ public class CarbonServerManager {
private String scriptName;
private static final String SERVER_STARTUP_MESSAGE = "WSO2 Micro Integrator started";
private int managementPort;
+ private int retryLimit = 3;
+ private int retryAttempt = 0;
public CarbonServerManager(AutomationContext context) {
this.automationContext = context;
@@ -148,8 +150,18 @@ public class CarbonServerManager {
waitTill(() -> !isRemotePortInUse("localhost", managementPort), 180, TimeUnit.SECONDS);
if (!isRemotePortInUse("localhost", managementPort)) {
+ if (retryAttempt < retryLimit) {
+ retryAttempt++;
+ log.info("Restarting server due to startup failure. Retry attempt: " + retryAttempt);
+ serverShutdown(portOffset, true);
+ startServerUsingCarbonHome(carbonHome, commandMap);
+ } else {
+ retryAttempt = 0;
throw new RuntimeException("Server initialization failed");
}
+ } else {
+ retryAttempt = 0;
+ }
log.info("Server started successfully ...");
