Dns$Companion$DnsSystem.lookup No address associated with hostname
Hello, I published my application on June 12. And this version, I upgraded okhttp library from 4.9.1 to 4.12.0. I am displaying a lot of the following error in try-catch block in firebase. (no changes were made on the server side) Is there anything I should check?
Thanks
Non-fatal Exception: java.lang.Exception: CallbackCreator-getDefaultCallback-onFailure exception detail:Unable to resolve host "xxxxxxx": No address associated with hostname
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:156)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
at java.net.InetAddress.getAllByName(InetAddress.java:1152)
at okhttp3.Dns$Companion$DnsSystem.lookup(Dns.kt:49)
at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.kt:169)
at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.kt:131)
at okhttp3.internal.connection.RouteSelector.next(RouteSelector.kt:73)
at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:205)
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.java:255)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
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:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
It seems likely that this issue is related to Firebase sending requests while the app is in the background. Some Android OEMs might block the internet connection for apps running in the background. As a result, the system's DNS lookup could cache failed requests, causing the first request after the app returns to the foreground to fail due to the cached DNS entry.
In theory, the failed DNS lookup cache has a TTL of around 2 seconds, so any request made after this period should be fine.
For more context, you can refer to the discussion in this related Retrofit issue: Retrofit issue #3915.
Hi...
Same problem here started 12th July. I think @ilkcansaricicek mean to say July and not June, accordingly to his chart. This is really weird and we're trying to find the root cause of this also but without success.
Take a look at the error that lead to crashes 👍
java.net.UnknownHostException: Unable to resolve host "api.mycompany.com": No address associated with hostname
at java.net.Inet6AddressImpl.lookupHostByName()(Inet6AddressImpl.java:124)
at java.net.Inet6AddressImpl.lookupAllHostAddr()(Inet6AddressImpl.java:103)
at java.net.InetAddress.getAllByName()(InetAddress.java:1152)
at okhttp3.Dns$Companion$DnsSystem.lookup()(Dns.kt:49)
at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress()(RouteSelector.kt:164)
at okhttp3.internal.connection.RouteSelector.nextProxy()(RouteSelector.kt:129)
at okhttp3.internal.connection.RouteSelector.next()(RouteSelector.kt:71)
at okhttp3.internal.connection.ExchangeFinder.findConnection()(ExchangeFinder.kt:205)
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection()(ExchangeFinder.kt:106)
at okhttp3.internal.connection.ExchangeFinder.find()(ExchangeFinder.kt:74)
at okhttp3.internal.connection.RealCall.initExchange$okhttp()(RealCall.kt:255)
at okhttp3.internal.connection.ConnectInterceptor.intercept()(ConnectInterceptor.kt:32)
at okhttp3.internal.http.RealInterceptorChain.proceed()(RealInterceptorChain.kt:109)
at okhttp3.internal.cache.CacheInterceptor.intercept()(CacheInterceptor.kt:95)
at okhttp3.internal.http.RealInterceptorChain.proceed()(RealInterceptorChain.kt:109)
at okhttp3.internal.http.BridgeInterceptor.intercept()(BridgeInterceptor.kt:83)
at okhttp3.internal.http.RealInterceptorChain.proceed()(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept()(RetryAndFollowUpInterceptor.kt:76)
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 com.mycompany.services.network.MyCompanyInterceptor.intercept()(MyCompanyInterceptor.kt:68)
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)
If anyone have workarounds or idea of how to fix this I would appreciate it.
Thanks Joao
@jricardooliveira Even with this failure, it shouldn't be leading to crashes. Are you missing some error handling around these requests? Or is this outside your control?
I'm having the 'Unable to resolve host "api.mycompany.com": No address associated with hostname' error too for a while now too. did anyone here managed to solve it?
Likely the same issue as https://github.com/firebase/firebase-android-sdk/issues/6419
Closing as not an OkHttp issue.
https://developer.android.com/about/versions/15/behavior-changes-all#background-network-access
In Android 15, apps that start a network request outside of a valid process lifecycle receive an exception. Typically, an UnknownHostException or other socket-related IOException. Network requests that happen outside of a valid lifecycle are usually due to apps unknowingly continuing a network request even after the app is no longer active.
To mitigate this exception, ensure your network requests are lifecycle aware and cancelled upon leaving a valid process lifecycle by using lifecycle aware components. If it is important that the network request should happen even when the user leaves the application, consider scheduling the network request using WorkManager or continue a user visible task using Foreground Service.