Summary
java.lang.IllegalArgumentException: networkResponse.priorResponse != null
at okhttp3.Response$Builder.checkSupportResponse(Response.kt:408)
at okhttp3.Response$Builder.networkResponse(Response.kt:394)
at com.apollographql.apollo.cache.http.HttpCacheInterceptor.networkFirst(HttpCacheInterceptor.java:111)
at com.apollographql.apollo.cache.http.HttpCacheInterceptor.intercept(HttpCacheInterceptor.java:51)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at com.globo.jarvis.JarvisClient$providerHeaderInterceptor$1.intercept(Unknown Source:219)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.kt:221)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
Version
2.4.4
Description
When I add the following cache rules and I get an error from the server (408, 500), the crash happens
@martinbonnin I'm from the Globoplay team
Hi @halysongoncalves, can you share your cache rules ?
```kotlin
internal fun buildApolloClient() = ApolloClient
.builder()
.serverUrl(settings.environment())
.httpCache(
ApolloHttpCache(
DiskLruHttpCacheStore(
File(
settings.application().cacheDir,
CACHE_APOLLO
), CACHE_SIZE
)
)
)
.defaultHttpCachePolicy(HttpCachePolicy.NETWORK_FIRST)
.useHttpGetMethodForQueries(true)
.useHttpGetMethodForPersistedQueries(true)
.enableAutoPersistedQueries(true)
.defaultHttpCachePolicy(HttpCachePolicy.NETWORK_FIRST)
.addCustomTypeAdapter(CustomType.DATE, DateTypeAdapter())
.okHttpClient(
OkHttpClient
.Builder()
.addInterceptor(providerInterceptorLogging(settings.enableLog()))
.addInterceptor(providerHeaderInterceptor())
.connectTimeout(settings.timeout(), TimeUnit.SECONDS)
.readTimeout(settings.timeout(), TimeUnit.SECONDS)
.writeTimeout(settings.timeout(), TimeUnit.SECONDS)
.build()
)
.build()
```
Thanks ! I'm suspecting something with the logging interceptor. The logging interceptor somehow reads the whole body and this doesn't seem to play super nice with the HTTP cache interceptor (see https://github.com/apollographql/apollo-android/issues/2968). Can you try without the logging interceptor?
I will do the test
I removed all the interceptors registered in okhttp, but the problem still persists:
Process: com.globo.globotv, PID: 6185
java.lang.IllegalArgumentException: networkResponse.priorResponse != null
at okhttp3.Response$Builder.checkSupportResponse(Response.kt:408)
at okhttp3.Response$Builder.networkResponse(Response.kt:394)
at com.apollographql.apollo.cache.http.HttpCacheInterceptor.networkFirst(HttpCacheInterceptor.java:111)
at com.apollographql.apollo.cache.http.HttpCacheInterceptor.intercept(HttpCacheInterceptor.java:51)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)

Thanks for trying that! Looks like it's something else then, maybe some interaction between the persisted queries and the cache. It's getting pretty late here but I'll try to reproduce first thing on Monday!
Thanks
@martinbonnin any news?
Arg very sorry ! Look like I forgot to hit enter this morning 馃う
I haven't been able to reproduce unfortunately so it looks like there's something more to the story. I made a small reproducer there: https://github.com/martinbonnin/apollo-android-samples/tree/main/apq-and-http-cache
Any chance you can see a difference with your setup and/or try to make it fail?
Hey @martinbonnin, sorry for the delay!
I am using the following very similar settings:


To simulate server error, I'm using charles proxy.
I ended up checking that when we force a 500 error, the cache works correctly and I get the answer.

However, if I force return 408 (time out), the app receives the crash!



I believe it is related to the http status code 408, only with it does the crash happen!
And when I remove all intercepts the crash is evident in the HttpCacheInterceptor class in the networkFirst method

Thanks ! That's an interesting scenario. Today I learnt about HTTP 208 and automatic retries ! Pull request there: https://github.com/apollographql/apollo-android/pull/3010/files
Awesome and thanks for the help!
2.5.5 is released with the fix, let me know how that goes!
@martinbonnin Everything working perfectly, thanks!