Skip to content

Commit

Permalink
JENKINS-33557 - tcp timeouts cause installer to hang for 6 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
kzantow committed Mar 22, 2016
1 parent 48a20ff commit 52c4ed6
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions core/src/main/java/hudson/model/UpdateCenter.java
Expand Up @@ -77,6 +77,8 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpRetryException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
Expand Down Expand Up @@ -1132,7 +1134,18 @@ public String getPluginRepositoryBaseUrl() {

private void testConnection(URL url) throws IOException {
try {
Util.copyStreamAndClose(ProxyConfiguration.open(url).getInputStream(),new NullOutputStream());
URLConnection connection = (URLConnection) ProxyConfiguration.open(url);
connection.setConnectTimeout(20000); // JENKINS-33557 lower connection test timeout (20 sec)
connection.connect();

if(connection instanceof HttpURLConnection) {
int responseCode = ((HttpURLConnection)connection).getResponseCode();
if(HttpURLConnection.HTTP_OK != responseCode) {
throw new HttpRetryException("Invalid response code (" + responseCode + ") from URL: " + url.toString(), responseCode);
}
} else {
Util.copyStreamAndClose(connection.getInputStream(),new NullOutputStream());
}
} catch (SSLHandshakeException e) {
if (e.getMessage().contains("PKIX path building failed"))
// fix up this crappy error message from JDK
Expand Down Expand Up @@ -1315,22 +1328,29 @@ public void run() {
return;
}
LOGGER.fine("Doing a connectivity check");
Future<?> internetCheck = null;
try {
String connectionCheckUrl = site.getConnectionCheckUrl();
final String connectionCheckUrl = site.getConnectionCheckUrl();
if (connectionCheckUrl!=null) {
connectionStates.put(ConnectionStatus.INTERNET, ConnectionStatus.CHECKING);
statuses.add(Messages.UpdateCenter_Status_CheckingInternet());
try {
config.checkConnection(this, connectionCheckUrl);
} catch (Exception e) {
if(e.getMessage().contains("Connection timed out")) {
// Google can't be down, so this is probably a proxy issue
connectionStates.put(ConnectionStatus.INTERNET, ConnectionStatus.FAILED);
statuses.add(Messages.UpdateCenter_Status_ConnectionFailed(connectionCheckUrl));
return;
// Run the internet check in parallel
internetCheck = updateService.submit(new Runnable() {
@Override
public void run() {
try {
config.checkConnection(ConnectionCheckJob.this, connectionCheckUrl);
} catch (Exception e) {
if(e.getMessage().contains("Connection timed out")) {
// Google can't be down, so this is probably a proxy issue
connectionStates.put(ConnectionStatus.INTERNET, ConnectionStatus.FAILED);
statuses.add(Messages.UpdateCenter_Status_ConnectionFailed(connectionCheckUrl));
return;
}
}
connectionStates.put(ConnectionStatus.INTERNET, ConnectionStatus.OK);
}
}
connectionStates.put(ConnectionStatus.INTERNET, ConnectionStatus.OK);
});
}

connectionStates.put(ConnectionStatus.UPDATE_SITE, ConnectionStatus.CHECKING);
Expand All @@ -1350,6 +1370,15 @@ public void run() {
statuses.add(Functions.printThrowable(e));
error = e;
}

if(internetCheck != null) {
try {
// Wait for internet check to complete
internetCheck.get();
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Error completing internet connectivity check: " + e.getMessage(), e);
}
}
}

private void addStatus(UnknownHostException e) {
Expand Down

0 comments on commit 52c4ed6

Please sign in to comment.