I’m experiencing an intermittent issue with my application that uses Jedis version 5.0.2 for Redis connectivity. The (random) error I’m encountering is:
Failed to connect to any host resolved for DNS name.
redis.clients.jedis.exceptions.JedisConnectionException: Failed to
connect to any host resolved for DNS name.
at redis.clients.jedis.DefaultJedisSocketFactory.connectToFirstSuccessfulHost(DefaultJedisSocketFactory.java:63)
at redis.clients.jedis.DefaultJedisSocketFactory.createSocket(DefaultJedisSocketFactory.java:87)
at redis.clients.jedis.Connection.connect(Connection.java:195)
at redis.clients.jedis.Connection.initializeFromClientConfig(Connection.java:393)
at redis.clients.jedis.Connection.(Connection.java:68)
at redis.clients.jedis.Jedis.(Jedis.java:220)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:170)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:571)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:298)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:223)
at redis.clients.jedis.util.Pool.getResource(Pool.java:38)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:378)
My application is deployed on Google Cloud. The issue appeared this past Friday randomly. Redeploying the application seemed to temporarily resolve it, but I want to do my due diligence in case it pops agains. My Jedis Version is 5.0.2.
Our SRE team verified that the DNS name resolves correctly to the Redis instance IPs and also checked firewall rules and VPC settings to ensure that traffic is allowed and correctly routed.
Is this a known issue with Jedis 5.0.2 or related to its DNS handling ? Are there any best practices or configuration settings I might be missing ? Would upgrading to a newer version of Jedis potentially resolve this issue?
Any insights or suggestions would be greatly appreciated !
2
As per Official Jedis guide :
“When the connection to Redis is lost or closed unexpectedly. Configure failover to handle this exception automatically with Resilience4J and the built-in Jedis failover mechanism. When you connect to a Redis with multiple endpoints,
such as Redis Enterprise Active-Active, it’s recommended to disable the JVM’s DNS cache to load-balance requests across multiple endpoints.
Jedis is a synchronous Java client for Redis. Use Lettuce if you need a more advanced Java client that also supports asynchronous and reactive connections. The sections below explain how to install Jedis and connect your application to a Redis database.”
I also recommend you to check the firewall and VPC settings. if any, open the port there.
ufw allow 6379
As your saying random error, check for network latency spikes, packet loss, or connection timeouts on your GCP during periods of application errors.
As per Dragonfly error-solution: Check Version Compatibility :
“Library and Server Versions: Verify compatibility between your Jedis library version and Redis server version. Sometimes, subtle issues arise from version mismatches. Check release notes and upgrade guides for any known issues.
Alternative Clients: If persistent issues occur, consider testing with another Redis client library to see if the problem persists. Alternatives like Lettuce might provide better results depending on your use case.”
Check this Jedis Release info for more details. Also refer to the similar open Github issue1 and issue2 for more information.