diff --git a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/HttpFeatureFlagFetcher.java b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/HttpFeatureFlagFetcher.java index d8fd1e71..971335bc 100644 --- a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/HttpFeatureFlagFetcher.java +++ b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/HttpFeatureFlagFetcher.java @@ -14,10 +14,12 @@ import java.io.File; import java.io.IOException; import java.net.URI; +import java.util.concurrent.TimeUnit; import okhttp3.Cache; import okhttp3.Call; import okhttp3.Callback; +import okhttp3.ConnectionPool; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; @@ -62,6 +64,11 @@ class HttpFeatureFlagFetcher implements FeatureFetcher { client = new OkHttpClient.Builder() .cache(new Cache(cacheDir, MAX_CACHE_SIZE_BYTES)) + .connectionPool(new ConnectionPool(0, 1, TimeUnit.MILLISECONDS)) + // We want a new connection each time, because keeping an idle connection alive + // could cause an unwanted wakeup due to connection-cleanup network traffic if + // it expires while the app is in the background. If we did not call + // .connectionPool() at all, OkHttp would default to a pool of non-zero size. .retryOnConnectionFailure(true) .build(); }