[Bug Report] Interceptor may throw a IllegalStateException: cache is closed
See original GitHub issueI am using the following code to add a custom header:
OkHttpClient.Builder builder = getBuilder()
.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request()
.newBuilder()
.addHeader("Session-Token", accessToken)
.build();
return chain.proceed(request);
}
});
But sometimes I get an error:
Fatal Exception: java.lang.IllegalStateException: cache is closed
at okhttp3.internal.DiskLruCache.checkNotClosed(DiskLruCache.java:635)
at okhttp3.internal.DiskLruCache.edit(DiskLruCache.java:453)
at okhttp3.internal.DiskLruCache.edit(DiskLruCache.java:447)
at okhttp3.Cache.put(Cache.java:244)
at okhttp3.Cache.access$000(Cache.java:135)
at okhttp3.Cache$1.put(Cache.java:147)
at okhttp3.internal.http.HttpEngine.maybeCache(HttpEngine.java:389)
at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:633)
at okhttp3.RealCall.getResponse(RealCall.java:241)
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
at co.voggle.core.ApiProvider$3.intercept(ApiProvider.java:149)
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
at okhttp3.RealCall.access$100(RealCall.java:30)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
The error makes sense but I don’t understand how to work around it, as I do not have the required objects in the intercept(Chain chain)
method to check if the cache is closed or not.
It would be okay to drop the call if the cache is closed.
I am using OkHttp via Retorofit for my android application
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (6 by maintainers)
Top Results From Across the Web
900946 – (JBPAPP6-1274) IllegalStateException: Cache is in ...
lang.IllegalStateException: Default cache is in 'TERMINATED' state and so it does not accept new invocations. Either restart it or recreate the cache container....
Read more >Retrofit : java.lang.IllegalStateException: closed - Stack Overflow
When I try to execute below code, in file named SynchronizationManager.kt, it gives me an error. var rulesResourcesServices = RetrofitInstance( ...
Read more >quarkus-cache interceptors and @NonBlocking methods
As a consequence of that change, the cache interceptors now contain an await() instruction which is causing the issue Rostislav found.
Read more >okhttp/src/main/java/com/squareup/okhttp/internal/http ...
<p>The request and response may be served by the HTTP response cache, by the ... @throws RouteException if the was a problem during...
Read more >Performing Basic Cache Operations - Coherence
An illegal state exception is thrown if an application attempts use a closed session or its resources. Use the close method to close...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
With great pain, I am using the following hack:
@MariannaVR how to resolve it,please? thanks!