We have a Java 8 application that fetches data from social media APIs constantly and we keep getting java.net.UnknownHostException <host>
(ex: java.net.UnknownHostException: graph.facebook.com
) eventually when accessing the URLs. That happens roughly in < 5% of the requests (which are around 50-100 per minute in total, segregated in different JVM instances).
Thing is, at first I thought we had a DNS or internet problem in our Azure server, so I set up a script in crontab that does nslookup
in both Instagram and Facebook APIs every minute, and after a whole day, not a single error occurred.
We connect through HTTPS using something like:
String facebookURL = "https://graph.facebook.com/v2.1/%s?access_token=%s&fields=name,picture&metadata=1";
// ... we replace the tokens here
HttpsURLConnection facebookConnection = (HttpsURLConnection) new URL(facebookURL).openConnection();
Any ideas on why we are getting this behavior or any other tests I could try? Would there be any SSL/socket limits that could produce the (wrong) java.net.UnknownHostException
, or is it something I have to live with?
As far as I know this exception is very straight forward, and our server is extremely stable in general.
We run our app in jdk1.8.0_111, Ubuntu 16.10 64bit and OpenSSL 1.0.2g.
Thanks :)