question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RedisCommandTimeoutException when there is a network glitch

See original GitHub issue

Hi,

We have a daemon process which pushes data to redis on AWS using lettuce-core. I have noticed that during network glitch i.e when a connection is disconnected , I get below exception :

io.lettuce.core.RedisCommandTimeoutException: Command timed out
at io.lettuce.core.LettuceFutures.awaitOrCancel(LettuceFutures.java:114)
at io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:62)
at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80)
at com.sun.proxy.$Proxy11.hmget(Unknown Source)

Code to reproduce :

public class TestMain {
	public static void main(String[] args) {
		Duration timeout = Duration.ofMillis(10000);
		RedisClient client = RedisClient.create(RedisURI.create("redis://127.0.0.1:6379"));
		client.setDefaultTimeout(timeout);
		RedisCommands<String, String> commands = client.connect().sync();
		String[] arr = { "test", "test2" };
		int i = 1;
		while (i <= 1000) {
			try {
				List<KeyValue<String, String>> op = commands.hmget("TEST", arr);
				System.out.println(op);
				i++;
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}

Version :

<dependency>
	<groupId>io.lettuce</groupId>
	<artifactId>lettuce-core</artifactId>
	<version>5.0.3.RELEASE</version>
</dependency>

After the connection is re-established it works fine. The time out given is around 10 seconds and network connection is fixed before 10 seconds but still this exception occur. Ideally it should have waited for 10 seconds before throwing the exception.

Also the exception thrown seems to be incorrect i.e RedisCommandTimeoutException , could have been something different.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
jaimesscommented, Oct 17, 2018

this params would mend it: echo “1” > /proc/sys/net/ipv4/tcp_keepalive_intvl echo “10” > /proc/sys/net/ipv4/tcp_keepalive_probes echo “6” > /proc/sys/net/ipv4/tcp_keepalive_time echo “3” > /proc/sys/net/ipv4/tcp_retries2

mp911de is right but it may worth have a look to cassandra or elasticsearch drivers which are able to recover from these problem

2reactions
jaimesscommented, Oct 18, 2018

diving a bit I found nettycustommizer, this works too:

    NettyCustomizer nettyCustomizer = new NettyCustomizer() {
        
        @Override
        public void afterChannelInitialized(Channel channel) {
            channel.pipeline().addLast(
                    new IdleStateHandler(readerIdleTimeSeconds, writerIdleTimeSeconds, allIdleTimeSeconds));
            channel.pipeline().addLast(new ChannelDuplexHandler() {
                @Override
                public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
                    if (evt instanceof IdleStateEvent) {
                        ctx.disconnect();
                    }
                }
            });
        }
        
        @Override
        public void afterBootstrapInitialized(Bootstrap bootstrap) {
        }
        
    };
    ClientResources res = DefaultClientResources.builder()
            .nettyCustomizer(nettyCustomizer ).build();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Command timed out after 1 minute(s) during load test
On reading about this (redis command timeout ) exception, we understand that this occurs due to connection issue (channel getting disconnected) or the...
Read more >
io.lettuce.core.RedisCommandTimeoutException: Command ...
Spring Boot provide it out of the box with almost no codding, Its just a matter of configuring your application.yml.
Read more >
Troubleshoot Azure Cache for Redis latency and timeouts
Learn how to resolve common latency and timeout issues with Azure Cache for Redis, such as Redis server patching and timeout exceptions.
Read more >
Troubleshooting - Amazon ElastiCache for Redis
Network ACLs are assigned to subnets, not specific resources. It is possible to have the same ACL assigned to ElastiCache and the client...
Read more >
lettuce-io/Lobby - Gitter
Unexpected error occurred in scheduled task. ... We have a ticket (lettuce-io/lettuce-core#795) but there was not sufficient interest from any side to come ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found