java.lang.IllegalStateException: closed when attempting to reference response body after interception
See original GitHub issue📢 Describe the bug
As mentioned in https://github.com/ChuckerTeam/chucker/pull/165#issuecomment-576393906, I needed to revert that diff in order to keep my app working.
I have several interceptors, a network interceptor, gson data adapter and rxjava2 call adapters setup and I use retrofit 1.7.1 and okhttp 3.14.6.
This might be something affecting just my specific setup, but wanted to document here in case anyone else is experiencing the issue. Copy/pasting my comment from PR #165 below, thanks!
Hey all, just a heads up as I was testing the develop branch within my app today. I had to revert the commit associated with this change since I was getting errors in the GsonResponseBodyConverter retrofit converter stage where it apparently tries to read the response but it has already been closed by the chucker interceptor by this change.
Caused by: java.lang.IllegalStateException: closed
at okio.RealBufferedSource.read(RealBufferedSource.java:48)
at okio.ForwardingSource.read(ForwardingSource.java:35)
at retrofit2.OkHttpCall$ExceptionCatchingResponseBody$1.read(OkHttpCall.java:296)
at okio.RealBufferedSource.select(RealBufferedSource.java:100)
at okhttp3.internal.Util.bomAwareCharset(Util.java:467)
at okhttp3.ResponseBody$BomAwareReader.read(ResponseBody.java:260)
at com.google.gson.stream.JsonReader.fillBuffer(JsonReader.java:1291)
at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1329)
at com.google.gson.stream.JsonReader.consumeNonExecutePrefix(JsonReader.java:1572)
at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:535)
at com.google.gson.stream.JsonReader.peek(JsonReader.java:426)
at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:55)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:39)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:223)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:186)
at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:45)
at io.reactivex.Observable.subscribe(Observable.java:12267)
at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
at io.reactivex.Observable.subscribe(Observable.java:12267)
at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
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:919)
This was using retrofit 1.7.1 and okhttp 3.14.6.
The result of this error was that none of the JSON API responses were parsed in my app, essentially preventing the app from working.
Let me know if any others experienced the same, thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Apologies for the delay here, I was able to test this out and it works as expected, thank you @vbuberen and @cortinico!
@kmayoral When you have time, please check latest
develop-SNAPSHOT
- just merged the fix for this issue from @cortinico