Java RxJAva / Retrofit / OkHttp组合看似随机InterruptedIOException

时间:2017-10-10 17:03:14

标签: java android retrofit2 okhttp

在Android应用中,我使用了

的组合

RxJava:1.3.0 回顾:2.3.0 okHttp:3.9.0

有大量的REST并行调用正在进行中,但是当调用拦截器的继续链时,我看到一个看似随机的InterruptedIOException,只是添加了一些auth头。我遇到的问题是我没有得到异常的上下文,所以我无法弄清楚原因,这不是暂停,我不会想到,因为无论我设置错误有多高似乎发生得很快。是否有可能取消呼叫,这是取消订阅的方式?

我需要知道的是这个InterruptedIOException的可能原因是什么,所以我可以搞清楚。这是异常树中的一些上下文。

感谢。

ZubieRetrofit: --> GET https://blah/blah/blah
ZubieRetrofit: User-Agent: qa 1.20.0
ZubieRetrofit: Authorization: Bearer xxxxx
ZubieRetrofit: Zubie-Identity-Provider: fred
ZubieRetrofit: Zubie-Account-Id: yyyyy
ZubieRetrofit: --> END GET
ZubieRetrofit: <-- HTTP FAILED: java.io.InterruptedIOException
ZubieRetrofit$ZubieCall: Exception thrown in ZubieCallInterceptor.intercept
java.io.InterruptedIOException
at okhttp3.internal.http2.Http2Stream.waitForIo(Http2Stream.java:579)
at okhttp3.internal.http2.Http2Stream.takeResponseHeaders(Http2Stream.java:143)
at okhttp3.internal.http2.Http2Codec.readResponseHeaders(Http2Codec.java:125)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:212)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at com.greenlight.zubie.network.ZubieRetrofit$ZubieCallInterceptor.intercept(ZubieRetrofit.java:1378)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:40)
at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:24)
at rx.internal.operators.OnSubscribeOnAssembly.call(OnSubscribeOnAssembly.java:96)
at rx.internal.operators.OnSubscribeOnAssembly.call(OnSubscribeOnAssembly.java:29)
at rx.Observable.unsafeSubscribe(Observable.java:10256)
at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)
at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:230)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
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:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)

1 个答案:

答案 0 :(得分:0)

添加自定义全局错误使用方有助于我解决类似的问题,因为okhttp或retrofit2-rxjava2-adapter似乎在rx订阅生命周期方面都不以安全的方式处理调用取消。

您可以查看其他讨论here