Bug 760614 - Retry on connection failures, to address transient network errors. r=nalexander

This commit is contained in:
Chenxia Liu 2012-06-04 18:07:31 -07:00
Родитель 4c5a2be266
Коммит c7a3ba74b1
1 изменённых файлов: 20 добавлений и 2 удалений

Просмотреть файл

@ -61,6 +61,8 @@ public class BaseResource implements Resource {
private static final int MAX_TOTAL_CONNECTIONS = 20;
private static final int MAX_CONNECTIONS_PER_ROUTE = 10;
private boolean retryOnFailedRequest = true;
public static boolean rewriteLocalhost = true;
private static final String LOG_TAG = "BaseResource";
@ -249,14 +251,30 @@ public class BaseResource implements Resource {
} catch (ClientProtocolException e) {
delegate.handleHttpProtocolException(e);
} catch (IOException e) {
delegate.handleHttpIOException(e);
Logger.debug(LOG_TAG, "I/O exception returned from execute.");
if (!retryOnFailedRequest) {
delegate.handleHttpIOException(e);
} else {
retryRequest();
}
} catch (Exception e) {
// Bug 740731: Don't let an exception fall through. Wrapping isn't
// optimal, but often the exception is treated as an Exception anyway.
delegate.handleHttpIOException(new IOException(e));
if (!retryOnFailedRequest) {
delegate.handleHttpIOException(new IOException(e));
} else {
retryRequest();
}
}
}
private void retryRequest() {
// Only retry once.
retryOnFailedRequest = false;
Logger.debug(LOG_TAG, "Retrying request...");
this.execute();
}
private void go(HttpRequestBase request) {
if (delegate == null) {
throw new IllegalArgumentException("No delegate provided.");