Background
I have an android app with > 100k active users. Some features of the app requires network interaction with a backend server. The backend server uses cloudflare DNS.
Issue
A couple of users get an UnknownHostException
when trying to access the backend.
A couple of actions in the app first communicate with google APIs before the error with the DNS resolution for my domain appears, so I'm pretty confident that the internet connectivity is working for the users. The error appears more or less randomly, I personally was never able to reproduce it.
I already read through:
- Does Android DNS need warm up?
- Android: Flush DNS
- java.net.UnknownHostException: Unable to resolve host "domain.com": No address associated with hostname
- https://android.stackexchange.com/questions/12962/how-can-i-flush-the-dns-cache
and searched the web, however most of the answers related to android <= 4.0. The users in question are using android 11-13 where the DNS caching issue should have been resolved.
I also had the thought that the users may only have an IPv6 address, but getAllByName
should still have resolved the IP addresses of the backend.
What I've tried so far
As a workaround I tried manually resolving the DNS entry using InetAddress.getAllByName
with up to 10 retries with 1sec delay between, since some posts I've found refer to android not being able to resolve the first request.
This however didn't help, users still get the same error from time to time.
I also tried setting
System.setProperty("networkaddress.cache.ttl", "5");
System.setProperty("networkaddress.cache.negative.ttl", "0");
although this probably doesn't have any impact on android anymore since android 5.
I don't want to go the route and manually resolve the records since the OS should handle that.
Question
Does anyone also have these kind of issues and know a workaround? As mentioned, manually resolving could be an option, but may fail on corporate networks where external DNS traffic is blocked.