0

I use okhttp for communicating between backend microservices. The service discovery is implemented on top of consul dns. As a result some instances/pods, associated to a given IP can be removed at any time. The problem is that okhttp caches the resolved ip address and when some associated instance becomes unavailable we see spikes of java.net.SocketTimeoutException.

I would like to understand, how does the dns cache is invalidated?

nicolattu
  • 191
  • 2
  • 11
  • 2
    This may help: https://stackoverflow.com/questions/1256556/how-to-make-java-honor-the-dns-caching-timeout – Patrick Mevzek Sep 22 '21 at 15:49
  • 1
    +1 to the link above. OkHttp isn't caching resolved ip address. But could be retaining a new deead connection from when it was first successfully used. – Yuri Schimke Sep 24 '21 at 06:23
  • Thanks, I should have mentioned that we already disable dns cache at jvm level using networkaddress.cache.ttl – nicolattu Sep 28 '21 at 06:01
  • @nicolattu did you ever resolve this issue? – tallkid24 May 06 '22 at 13:33
  • @tallkid24 yes, I did a network interceptor with a try catch, and when there is timeout exception i close the socket of the current connection, next request does dns lookup again. – nicolattu May 31 '22 at 19:34

0 Answers0