4

Bumped into an issue where my application using https://github.com/square/okhttp - okhttp version - 3.12.1 is not able to connect to a domain even though I've provided the Internet Permission in the AndroidManifest.xml

The user was, however, able to connect to the internet on their device and use other apps, based on their review comments.

For now, I am unable to reproduce the exception and hence if anyone who has experienced this issue before could help me understand better.

I cannot upgrade the library at the moment as I don't want to introduce a big change.

Stacktrace

Caused by: java.net.UnknownHostException: Unable to resolve host "domain.com": 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$-CC.lambda$static$0(SourceFile:39)
    at okhttp3.-$$Lambda$Dns$mTkNcZf2K4euny3_jks6Cac6Az0.lookup(Unknown Source:0)
    at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(SourceFile:185)
    at okhttp3.internal.connection.RouteSelector.nextProxy(SourceFile:149)
    at okhttp3.internal.connection.RouteSelector.next(SourceFile:84)
    at okhttp3.internal.connection.StreamAllocation.findConnection(SourceFile:214)
    at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(SourceFile:135)
    at okhttp3.internal.connection.StreamAllocation.newStream(SourceFile:114)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(SourceFile:42)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(SourceFile:94)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(SourceFile:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(SourceFile:125)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at com.appdynamics.eumagent.runtime.a.a$a.intercept(SourceFile:108)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(SourceFile:264)
    at okhttp3.RealCall.execute(SourceFile:93)

Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
    at libcore.io.Linux.android_getaddrinfo(Native Method)
    at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
    at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:200)
    at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
    at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
    ... 39 more
scout
  • 307
  • 1
  • 3
  • 8

4 Answers4

0

I usally have that error using Retrofit (with Okhttp as client), it happens when the device doesn't have any internet conection (both WIFI or mobile data) or my server endpoint is down. Try it yourself! But there are several factors else; like runtime request permisions or the network security config.

Hope this helps, bro.

Sampa
  • 181
  • 1
  • 6
  • 2
    the users affected by this issue state that they have an internet connection as they are able to use other apps. The server endpoint is also up and running with no errors hence iOS users are not affected. There are no network security config rules that are linked to the AndroidManifest. – scout Jan 14 '20 at 02:24
  • I am facing similar issue did you find any solution? – Kartik Garasia Sep 04 '22 at 13:05
0

We solved this issue by making a few DNS changes.

  • Reduced few CNAME records.
  • Reduced TTL.

No code changes were made on the android client.

scout
  • 307
  • 1
  • 3
  • 8
0

Based on the user's ISP it may occur, I think the best way to guarantee that the domain gets resolved is using a custom DNS Resolver using a Custom Caching mechanism based on the needs.
Sometimes ISPs/Routers cache the DNS response based on the first Query,
So most of the time you ask for the record from the primary DNS servers it works. Take a look at https://square.github.io/okhttp/4.x/okhttp/okhttp3/-dns/

Koorosh Ghorbani
  • 507
  • 4
  • 14
-1

I was facing a similar issue while using Volley in android. The issue got resolved after invalidating the cache and restarting the project.

In Android Studio, File -> Invalidate Caches -> Select all checkboxes -> Invalidate cache and Restart.

HKST
  • 1