Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #597 from zalando/issue-491
Browse files Browse the repository at this point in the history
Adding retry to getHttpClient when "No System TLS" pops up #491
  • Loading branch information
diemol committed May 30, 2018
2 parents b393424 + 00cb88d commit 95a48ce
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@
import org.openqa.grid.web.Hub;
import org.openqa.grid.web.servlet.handler.RequestHandler;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.server.log.LoggingManager;

import de.zalando.ep.zalenium.proxy.AutoStartProxySet;
import de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy;
import de.zalando.ep.zalenium.proxy.DockeredSeleniumStarter;
import de.zalando.ep.zalenium.util.ZaleniumConfiguration;

import java.net.URL;
import java.time.Clock;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -79,7 +82,6 @@ public ZaleniumRegistry(Hub hub) {
*
* @param hub the {@link Hub} to associate this registry with
* @param proxySet the {@link ProxySet} to manage proxies with
* @return the registry
*/
public ZaleniumRegistry(Hub hub, ProxySet proxySet) {
super(hub);
Expand Down Expand Up @@ -449,6 +451,34 @@ public void uncaughtException(Thread t, Throwable e) {
}
}

@Override
public HttpClient getHttpClient(URL url) {
// https://github.com/zalando/zalenium/issues/491
int maxTries = 3;
for (int i = 1; i <= maxTries; i++) {
try {
HttpClient client = httpClientFactory.createClient(url);
if (i > 1) {
String message = String.format("Successfully created HttpClient for url %s, after attempt #%s", url, i);
LOG.warn(message);
}
return client;
} catch (Exception | AssertionError e) {
String message = String.format("Error while getting the HttpClient for url %s, attempt #%s", url, i);
LOG.debug(message, e);
if (i == maxTries) {
throw e;
}
try {
Thread.sleep((new Random().nextInt(5) + 1) * 1000);
} catch (InterruptedException exception) {
LOG.error("Something went wrong while delaying the HttpClient creation after a failed atttempt", exception);
}
}
}
throw new IllegalStateException(String.format("Something went wrong while creating a HttpClient for url %s", url));
}

/**
* iterates the queue of incoming new session request and assign them to proxy after they've been
* sorted by priority, with priority defined by the prioritizer.
Expand Down

0 comments on commit 95a48ce

Please sign in to comment.