You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if I make a request when I’m offline and I know I should get a cached response from OkHttp, it throws an exception instead of returning the cached response if It can’t resolve the hostname (java.net.UnknownHostException). However, if it was able to make a successful request to that URL before, then it happily returns from the cache, even though I’m offline.
I can easily reproduce this with the following steps:
Open the app (while online);
Make a request and make sure the response is successful and properly cached by OkHttp;
Kill the app;
Set the device to Airplane mode;
Reopen the app;
Make same request again;
Observe that it fails;
If I follow the same steps above, but skipping step 3 (kill the app), it works correctly.
Heres the stack trace (there is an interceptor in the middle):
W java.net.UnknownHostException: Unable to resolve host "api.example.com": No address associated with hostname
W at java.net.InetAddress.lookupHostByName(InetAddress.java:457)
W at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
W at java.net.InetAddress.getAllByName(InetAddress.java:215)
W at com.squareup.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)
W at com.squareup.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:188)
W at com.squareup.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:157)
W at com.squareup.okhttp.internal.http.RouteSelector.next(RouteSelector.java:100)
W at com.squareup.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:357)
W at com.squareup.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:340)
W at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)
W at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
W at com.squareup.okhttp.Call.getResponse(Call.java:273)
W at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230)
W at com.example.MyInterceptor.intercept(MyInterceptor.java:35)
W at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:227)
W at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201)
W at com.squareup.okhttp.Call.access$100(Call.java:36)
W at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:164)
W at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
W at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W at java.lang.Thread.run(Thread.java:818)
W Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
W at libcore.io.Posix.android_getaddrinfo(Native Method)
W at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
W at java.net.InetAddress.lookupHostByName(InetAddress.java:438)
W ... 21 more
OkHttp version 2.4.0
The text was updated successfully, but these errors were encountered:
felipecsl
changed the title
OkHttp fails to return cached response if it can't resolve the host
OkHttp fails to return cached response after app cold start when offline
Jun 25, 2015
Never mind, I screwed up with the okhttp disk cache directory. Had it being used by something else and this was causing a conflict or something, then all the cached files were getting deleted upon app startup. Closing...
if I make a request when I’m offline and I know I should get a cached response from OkHttp, it throws an exception instead of returning the cached response if It can’t resolve the hostname (java.net.UnknownHostException). However, if it was able to make a successful request to that URL before, then it happily returns from the cache, even though I’m offline.
I can easily reproduce this with the following steps:
If I follow the same steps above, but skipping step 3 (kill the app), it works correctly.
Heres the stack trace (there is an interceptor in the middle):
OkHttp version 2.4.0
The text was updated successfully, but these errors were encountered: