Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nagesh-sys opened this issue Jun 28, 2024 · 3 comments
Labels
waiting-for-feedback We need additional information before we can continue

Comments

@nagesh-sys
Copy link

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
Copy link

riham888 commented Aug 15, 2024

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?

@taylorbasso
Copy link

+1 same random error and stack trace. Will work fine for days and randomly get the error.

Interestingly, also using Azure Cache for Redis.

Jedis 4.3.2

@ggivo ggivo added the waiting-for-feedback We need additional information before we can continue label May 23, 2025
@ggivo
Copy link
Collaborator

ggivo commented May 23, 2025

@taylorbasso @nagesh-sys

Based on the stack trace, a connect timed out error typically means the client couldn’t reach the Redis host — often due to DNS issues or network unavailability.

The exception message "Failed to connect to any host resolved for DNS name" was improved to include the contacted HostAndPort and detailed errors from each connection attempt (as suppressed exceptions). This should help clarify whether DNS resolution worked and why individual connections failed.

If needed, retry logic can be handled at the application level, or you can use RetryableCommandExecutor.

Without reliable steps to reproduce, I don’t think this issue is actionable at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-feedback We need additional information before we can continue
Projects
None yet
Development

No branches or pull requests

4 participants