redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out #392

Closed
ricabalta opened this Issue Feb 5, 2013 · 6 comments

Projects

None yet

4 participants

@ricabalta

Hi,

Now and then I'm getting the following exception when getting a resource from pool:

exception:

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
    at redis.clients.jedis.Protocol.process(Protocol.java:79)
    at redis.clients.jedis.Protocol.read(Protocol.java:131)
    at redis.clients.jedis.Connection.getBinaryMultiBulkReply(Connection.java:199)
    at redis.clients.jedis.Jedis.keys(Jedis.java:179)
    at com.comut.utils.dao.RedisDAO.keys(RedisDAO.java:105)
Caused by: java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at java.net.SocketInputStream.read(SocketInputStream.java:90)
    at redis.clients.util.RedisInputStream.fill(RedisInputStream.java:109)
    at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:45)
    at redis.clients.jedis.Protocol.process(Protocol.java:64)

code:

import java.util.Set;

import org.apache.commons.pool.impl.GenericObjectPool;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import com.comut.utils.exception.CacheException;
import com.comut.utils.interfaces.IRedis;

public class RedisDAO extends AbstractDAO implements IRedis{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private static final Integer PORT = 6379;

    private static final String HOST = "10.0.0.125";

    private JedisPool jedisPool = null;

    private JedisPool getJedis(){
        if(this.jedisPool == null){
            GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();
            poolConfig.maxActive = 100;
            poolConfig.maxIdle = 10;
            poolConfig.minIdle = 2;
            poolConfig.maxWait = 100;
            poolConfig.testWhileIdle = true;
            poolConfig.testOnBorrow = true;
            poolConfig.testOnReturn = true;
            poolConfig.minEvictableIdleTimeMillis = 10000;
            poolConfig.timeBetweenEvictionRunsMillis = 5000;
            poolConfig.numTestsPerEvictionRun = 10;

            this.jedisPool = new JedisPool(poolConfig, HOST, PORT);
        }
        return this.jedisPool;
    }

    /**
     * Get the cache client
     * @return the {@link Jedis}
     * @throws Exception
     */
    private Jedis getCache(){
        return this.getJedis().getResource();
    }

    private void returnCache(Jedis cache){
        this.getJedis().returnResource(cache);
    }

    @Override
    public String get(String key) throws CacheException{
        Jedis cache = this.getCache();
        try{
            return cache.get(key);
        } finally {
            this.returnCache(cache);
        }
    }

    @Override
    public void set(String key, String value){
        Jedis cache = this.getCache();
        try{
            cache.set(key, value);
        } finally {
            this.returnCache(cache);
        }

    }

    @Override
    public void del(String key){
        Jedis cache = this.getCache();
        try{
            cache.del(key);
        } finally {
            this.returnCache(cache);
        }
    }

    @Override
    public void flush(){
        Jedis cache = this.getCache();
        try{
            cache.flushAll();
        } finally {
            this.returnCache(cache);
        }
    }

    @Override
    public Set<String> keys(String pattern){
        Jedis cache = this.getCache();
        try{
            return cache.keys(pattern);
        } finally {
            this.returnCache(cache);
        }
    }

    @Override
    public void disconnect() {
        Jedis cache = this.getCache();
        try{
            cache.disconnect();
        } finally {
            this.returnCache(cache);
        }
    }

}

maven:

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.1.0</version>
    <scope>compile</scope>
</dependency>

redis:

2.6.9

Can anyone help with this issue?

@xetorthio
Owner
@ricabalta

About 2 to 3K keys.

Only thing that might cause any issue is the keys(pattern) usage. I used it a lot.

@ricabalta

Any help available would be very much appreciated!!!

@xetorthio
Owner
@jmlogan

We were having the same issue, with the keys command taking ~1 second to run.

Is there a way to specify a larger timeout value?

@xetorthio
Owner
@marcosnils marcosnils closed this May 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment