redis / jedis

Redis Java client
https://redis.github.io/jedis/
MIT License
11.88k stars 3.87k forks source link

redis.clients.jedis.exceptions.JedisConnectionException: Failed to connect to any host resolved for DNS name. #3877

Open nagesh-sys opened 4 months ago

nagesh-sys commented 4 months ago

Expected behavior

Failed to perform put and get operations into Redis

Here is the stack trance

redis.clients.jedis.exceptions.JedisConnectionException: Failed to connect to any host resolved for DNS name.
    at redis.clients.jedis.DefaultJedisSocketFactory.connectToFirstSuccessfulHost(DefaultJedisSocketFactory.java:63) ~[jedis-5.1.2.jar:?]
    at redis.clients.jedis.DefaultJedisSocketFactory.createSocket(DefaultJedisSocketFactory.java:89) ~[jedis-5.1.2.jar:?]
    at redis.clients.jedis.Connection.connect(Connection.java:194) ~[jedis-5.1.2.jar:?]
    at redis.clients.jedis.Connection.initializeFromClientConfig(Connection.java:392) ~[jedis-5.1.2.jar:?]
    at redis.clients.jedis.Connection.<init>(Connection.java:67) ~[jedis-5.1.2.jar:?]
    at redis.clients.jedis.ConnectionFactory.makeObject(ConnectionFactory.java:59) ~[jedis-5.1.2.jar:?]
    at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:566) ~[commons-pool2-2.12.0.jar:2.12.0]
    at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:306) ~[commons-pool2-2.12.0.jar:2.12.0]
    at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:233) ~[commons-pool2-2.12.0.jar:2.12.0]
    at redis.clients.jedis.util.Pool.getResource(Pool.java:38) ~[jedis-5.1.2.jar:?]
    at redis.clients.jedis.ConnectionPool.getResource(ConnectionPool.java:29) ~[jedis-5.1.2.jar:?]
    at redis.clients.jedis.ConnectionPool.getResource(ConnectionPool.java:7) ~[jedis-5.1.2.jar:?]
    at redis.clients.jedis.providers.PooledConnectionProvider.getConnection(PooledConnectionProvider.java:68) ~[jedis-5.1.2.jar:?]
    at redis.clients.jedis.executors.DefaultCommandExecutor.executeCommand(DefaultCommandExecutor.java:23) ~[jedis-5.1.2.jar:?]
    at redis.clients.jedis.UnifiedJedis.executeCommand(UnifiedJedis.java:252) ~[jedis-5.1.2.jar:?]
    at redis.clients.jedis.UnifiedJedis.get(UnifiedJedis.java:730) ~[jedis-5.1.2.jar:?]

I configured the JedisPool like below

var redisHostName = System.getenv("REDIS_HOST");
        var redisPort = null !=  System.getenv("REDIS_PORT") ? Integer.parseInt(System.getenv("REDIS_PORT")) : 6379;
        var redisUserName = System.getenv("REDIS_USERNAME");
        var redisPassword = System.getenv("REDIS_PASSWORD");

        GenericObjectPoolConfig<Jedis> poolConfig = new GenericObjectPoolConfig<>();
        poolConfig.setMaxTotal(2000); // Set maximum number of connections
        poolConfig.setMaxIdle(300);  // Set maximum number of idle connections
        poolConfig.setMinIdle(100);   // Set minimum number of idle connections
        int timeout = 60000;

         JedisPool jedispool= new JedisPool(poolConfig, redisHostName, redisPort, timeout, redisUserName, redisPassword);

Redis / Jedis Configuration

Jedis version: 5.1.2

Java version: java 11

org.apache.commons : commons-pool2 2.12.0

riham888 commented 3 months ago

we have the same issue:

image

down in the trace, caused by socket timeout:

image

so it resolves the Redis URL into an IP address and then tries to open a new socket which then fails with socket timeout... running in Azure, Azure cache for Redis it is jedis 5.1.0.

perhaps some kind of retry mechanism to be used?