From c7a3ba74b1cc683d56914ed2273b2cb28ec09c9c Mon Sep 17 00:00:00 2001 From: Chenxia Liu <liuche@mozilla.com> Date: Mon, 4 Jun 2012 18:07:31 -0700 Subject: [PATCH] Bug 760614 - Retry on connection failures, to address transient network errors. r=nalexander --- .../android/base/sync/net/BaseResource.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/mobile/android/base/sync/net/BaseResource.java b/mobile/android/base/sync/net/BaseResource.java index fa3762cfda840..5f86df4b2017c 100644 --- a/mobile/android/base/sync/net/BaseResource.java +++ b/mobile/android/base/sync/net/BaseResource.java @@ -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."); -- GitLab