Skip to content

Commit

Permalink
Merge dc0f5ec into master
Browse files Browse the repository at this point in the history
  • Loading branch information
realm-ci committed Oct 25, 2017
2 parents d15b833 + dc0f5ec commit fb6dac0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* Fix some potential database corruption caused by deleting the Realm file while a Realm instance are still opened in another process or the sync client thread.
* Added `realm.ignoreKotlinNullability` as a kapt argument to disable treating kotlin non-null types as `@Required` (#5412) (introduced in `v3.6.0`).
* Increased http connect/write timeout for low bandwidth network.

* [ObjectServer] now retrying network query when encountering any `IOException` (#5453).

## 4.0.0 (2017-10-16)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package io.realm;

import java.net.ConnectException;

import java.io.IOException;

/**
* This class enumerate all potential errors related to using the Object Server or synchronizing data.
Expand Down Expand Up @@ -200,8 +201,12 @@ public static ErrorCode fromInt(int errorCode) {
* @return mapped {@link ErrorCode}.
*/
public static ErrorCode fromException(Exception exception) {
// ConnectException is recoverable (with exponential backoff)
return (exception instanceof ConnectException) ? ErrorCode.IO_EXCEPTION : ErrorCode.UNKNOWN;
// IOException are recoverable (with exponential backoff)
if (exception instanceof IOException) {
return ErrorCode.IO_EXCEPTION;
} else {
return ErrorCode.UNKNOWN;
}
}

public enum Category {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void logout() {
final Token refreshTokenToBeRevoked = refreshToken;

ThreadPoolExecutor networkPoolExecutor = SyncManager.NETWORK_POOL_EXECUTOR;
networkPoolExecutor.submit(new ExponentialBackoffTask<LogoutResponse>() {
networkPoolExecutor.submit(new ExponentialBackoffTask<LogoutResponse>(3) {

@Override
protected LogoutResponse execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
* Abstracts the concept of running an network task with incremental backoff. It will run forever until interrupted.
*/
public abstract class ExponentialBackoffTask<T extends AuthServerResponse> implements Runnable {
private final int maxRetries;

public ExponentialBackoffTask(int maxRetries) {
this.maxRetries = maxRetries;
}

public ExponentialBackoffTask() {
this(Integer.MAX_VALUE - 1);
}

// Task to perform
protected abstract T execute();
Expand Down Expand Up @@ -69,7 +78,7 @@ public void run() {
onSuccess(response);
break;
} else {
if (shouldAbortTask(response)) {
if (shouldAbortTask(response) || attempt == maxRetries + 1) {
onError(response);
break;
}
Expand Down

0 comments on commit fb6dac0

Please sign in to comment.