Android:无法处理UnknownHostException [使用Retrofit 2,okhttp3,rxandroid 2]

时间:2017-03-31 07:41:36

标签: java android rx-android okhttp3

我有一个已经投入生产一段时间的Android应用程序。我收到了Firebase的致命报告(日志在下面),但我不清楚下次如何避免它。

我在java.net.UnknownHostException Unable to resolve host "accounts.google.com": No address associated with hostname while inserting rows in bigquery找到了类似的堆栈跟踪,但他们可以通过以下方式解决它:

<uses-permission android:name="android.permission.INTERNET" />

但那不是我的情况。

对于网络通信,我使用:

  • Retrofit 2
  • okhttp 3
  • 用于Retrofit 2的rxjava2适配器

使用此设置,所有错误都会在rx subscribe中的onError函数中结束。我在所有HTTP调用中处理UnknownHostException,但即使我没有,它也应该报告非致命作为最坏的情况。

我不知道如何重现这个bug。堆栈跟踪不是很有用,因为它没有指向我的应用程序。

有关如何重现错误和任何其他见解的任何想法都会受到很多关注。

这是堆栈跟踪:

Exception java.net.UnknownHostException: Unable to resolve host "rest.mywebsite.com": No address associated with hostname
java.net.InetAddress.lookupHostByName (InetAddress.java:470)
java.net.InetAddress.getAllByNameImpl (InetAddress.java:252)
java.net.InetAddress.getAllByName (InetAddress.java:215)
okhttp3.Dns$1.lookup (Dns.java)
okhttp3.internal.connection.RouteSelector.hasNext (RouteSelector.java)
<OR>.connectFailed (RouteSelector.java)
<OR>.resetNextProxy (RouteSelector.java)
<OR>.resetNextInetSocketAddress (RouteSelector.java)
<OR>.getHostString (RouteSelector.java)
okhttp3.internal.connection.RouteSelector.nextProxy (RouteSelector.java)
okhttp3.internal.connection.RouteSelector.next (RouteSelector.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.ConnectInterceptor.intercept (ConnectInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.cache.CacheInterceptor.intercept (CacheInterceptor.java)
<OR>.stripBody (CacheInterceptor.java)
<OR>.maybeCache (CacheInterceptor.java)
<OR>.cacheWritingResponse (CacheInterceptor.java)
<OR>.combine (CacheInterceptor.java)
<OR>.isEndToEnd (CacheInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.java)
<OR>.cookieHeader (BridgeInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RetryAndFollowUpInterceptor.cancel (RetryAndFollowUpInterceptor.java)
<OR>.setCallStackTrace (RetryAndFollowUpInterceptor.java)
<OR>.intercept (RetryAndFollowUpInterceptor.java)
<OR>.createAddress (RetryAndFollowUpInterceptor.java)
<OR>.recover (RetryAndFollowUpInterceptor.java)
<OR>.isRecoverable (RetryAndFollowUpInterceptor.java)
<OR>.followUpRequest (RetryAndFollowUpInterceptor.java)
<OR>.sameConnection (RetryAndFollowUpInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.logging.HttpLoggingInterceptor.setLevel (HttpLoggingInterceptor.java)
<OR>.intercept (HttpLoggingInterceptor.java)
<OR>.isPlaintext (HttpLoggingInterceptor.java)
<OR>.bodyEncoded (HttpLoggingInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java)
okhttp3.RealCall$AsyncCall.execute (RealCall.java)
okhttp3.internal.NamedRunnable.run (NamedRunnable.java)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1113)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:588)
java.lang.Thread.run (Thread.java:818)

Caused by android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
libcore.io.Posix.android_getaddrinfo (Posix.java)
libcore.io.ForwardingOs.android_getaddrinfo (ForwardingOs.java:55)
java.net.InetAddress.lookupHostByName (InetAddress.java:451)
java.net.InetAddress.getAllByNameImpl (InetAddress.java:252)
java.net.InetAddress.getAllByName (InetAddress.java:215)
okhttp3.Dns$1.lookup (Dns.java)
okhttp3.internal.connection.RouteSelector.hasNext (RouteSelector.java)
<OR>.connectFailed (RouteSelector.java)
<OR>.resetNextProxy (RouteSelector.java)
<OR>.resetNextInetSocketAddress (RouteSelector.java)
<OR>.getHostString (RouteSelector.java)
okhttp3.internal.connection.RouteSelector.nextProxy (RouteSelector.java)
okhttp3.internal.connection.RouteSelector.next (RouteSelector.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.ConnectInterceptor.intercept (ConnectInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.cache.CacheInterceptor.intercept (CacheInterceptor.java)
<OR>.stripBody (CacheInterceptor.java)
<OR>.maybeCache (CacheInterceptor.java)
<OR>.cacheWritingResponse (CacheInterceptor.java)
<OR>.combine (CacheInterceptor.java)
<OR>.isEndToEnd (CacheInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.java)
<OR>.cookieHeader (BridgeInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RetryAndFollowUpInterceptor.cancel (RetryAndFollowUpInterceptor.java)
<OR>.setCallStackTrace (RetryAndFollowUpInterceptor.java)
<OR>.intercept (RetryAndFollowUpInterceptor.java)
<OR>.createAddress (RetryAndFollowUpInterceptor.java)
<OR>.recover (RetryAndFollowUpInterceptor.java)
<OR>.isRecoverable (RetryAndFollowUpInterceptor.java)
<OR>.followUpRequest (RetryAndFollowUpInterceptor.java)
<OR>.sameConnection (RetryAndFollowUpInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.logging.HttpLoggingInterceptor.setLevel (HttpLoggingInterceptor.java)
<OR>.intercept (HttpLoggingInterceptor.java)
<OR>.isPlaintext (HttpLoggingInterceptor.java)
<OR>.bodyEncoded (HttpLoggingInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java)
okhttp3.RealCall$AsyncCall.execute (RealCall.java)
okhttp3.internal.NamedRunnable.run (NamedRunnable.java)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1113)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:588)
java.lang.Thread.run (Thread.java:818)

手机已从网络断开,并且在Android 6.0.1上发生。

1 个答案:

答案 0 :(得分:1)

问题导致嵌套的Rx调用。当我从一个Rx调用中取消订阅时,嵌套的一个仍然存在并导致崩溃。