Java service keeps connecting to an old IP long after the DNS record changed.
IntermediateTroubleshootingDNS resolution failures
Answer
Likely causes → JVM DNS cache. With a security manager installed, networkaddress.cache.ttl defaults to forever; otherwise 30 s. Connection pools also keep existing connections to the old IP.
Diagnose →
jcmd <pid> VM.system_properties | grep -i networkaddress
grep -i networkaddress $JAVA_HOME/conf/security/java.security
ss -tnp | grep java
Fix → Set networkaddress.cache.ttl=60 in java.security or -Dsun.net.inetaddr.ttl=60, and set pool max connection lifetime so connections reopen.
Prevent → Standardize JVM DNS TTL in base images.
More on DNS resolution failures
`dig app.example.com` returns `status: NXDOMAIN`.Beginner`dig` returns `status: SERVFAIL` for one domain while other domains resolve fine.Intermediate`curl: (6) Could not resolve host: api.example.com` inside a container but it resolves on the host.BeginnerA DNS change was made 2 hours ago, but some users still reach the old IP.BeginnerIn Kubernetes, external lookups from pods are slow and CoreDNS logs show many NXDOMAIN queries like `api.stripe.com.default.svc.cluster.local`.IntermediatePods intermittently log `dial tcp: lookup orders on 10.96.0.10:53: i/o timeout`, about 5 seconds per failure.Advanced