2

I am seeing a spike in these types of errors in my production app via logs:

"Unable to resolve host "{my.api.website}": No address associated with hostname"

The site / API works for 99.9% of people and I am only seeing this intermittently.

It appears as though it is an issue with internet connectivity as per these links:

I have therefore setup some retry logic so that it will make another attempt, but the problem is that I am unsure how to actually intentionally trigger this exception using an Android device (either emulator or live) to see if the new fix works.

How would I go about manually triggering a java.lang.exception where the site I am hitting throws this unable to resolve host issue?

PGMacDesign
  • 6,092
  • 8
  • 41
  • 78

1 Answers1

2

You can trigger an UnknownHostException by spelling the host name incorrectly. The cause of the error won't be the same, but at least you'll get the same class of exception.

Out there "in the wild" this exception can happen for a number of reasons, including:

  • device loses connection to the network during or shortly before host name resolution
  • device connects to a captive portal that intercepts DNS requests or is not connected to the Internet
  • DNS request fails or times out for any other random reason

DNS request timeouts are a particularly insidious problem. They are difficult to reproduce. The default timeout is way too long, longer than users are willing to wait, and there's no way to change it. Developers have to resort to hacks like this: Can I set the getaddrinfo timeout in Android for DefaultHttpClient?

Joni
  • 108,737
  • 14
  • 143
  • 193
  • Great answer and ty for the link. I will just integrate that in as a cache check and hopefully it will help to at least allow for quicker `Retry Request?` Dialog popups. – PGMacDesign Apr 14 '20 at 21:37