2

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:

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.

davidgiga1993
  • 2,695
  • 18
  • 30
  • Have you found any solution for this? because I am also getting the same error from my user. I tell them to restart the device and it gets working then, But what is the reason behind this error? – Gulab Sagevadiya Aug 16 '23 at 10:05
  • Well sort of, first of all I overlooked that this property is not System.setProperty() but Security.setProperty() which improved the DNS behavior after a loss of connection (no app restart required anymore). Then I've implemented manual DNS resolution before making the actual request – davidgiga1993 Aug 19 '23 at 07:21

0 Answers0