Skip to content
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

Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Unknown reply: p #1936

Closed
rs10615 opened this issue Jan 20, 2019 · 7 comments

Comments

@rs10615
Copy link

rs10615 commented Jan 20, 2019

org.springframework.data.redis.RedisConnectionFailureException: Unknown reply: a; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Unknown reply: a
        at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:67)
        at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:41)
        at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
        at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
        at org.springframework.data.redis.connection.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:181)
        at org.springframework.data.redis.connection.jedis.JedisHashCommands.convertJedisAccessException(JedisHashCommands.java:433)
        at org.springframework.data.redis.connection.jedis.JedisHashCommands.hGetAll(JedisHashCommands.java:196)
        at org.springframework.data.redis.connection.DefaultedRedisConnection.hGetAll(DefaultedRedisConnection.java:862)
        at org.springframework.data.redis.core.DefaultHashOperations.lambda$entries$12(DefaultHashOperations.java:231)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
        at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
        at org.springframework.data.redis.core.DefaultHashOperations.entries(DefaultHashOperations.java:231)
        at com.nec.edgedisplay.common.doatier.redis.services.impl.DemographicRedisServiceImpl.findAll(DemographicRedisServiceImpl.java:88)
        at com.nec.edgedisplay.common.doatier.redis.services.impl.DemographicRedisServiceImpl$$FastClassBySpringCGLIB$$5cda2f2d.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
        at com.nec.edgedisplay.common.doatier.redis.services.impl.DemographicRedisServiceImpl$$EnhancerBySpringCGLIB$$25b48e11.findAll(<generated>)
        at com.nec.edgedisplay.common.biztier.services.impl.DemographicServiceImpl.sendDataToEventHub(DemographicServiceImpl.java:67)
        at com.nec.edgedisplay.da.scheduler.EventHubScheduler.scheduleDemographicCacheTransferToEventHub(EventHubScheduler.java:60)
        at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Unknown reply: a
        at redis.clients.jedis.Protocol.process(Protocol.java:164)
        at redis.clients.jedis.Protocol.read(Protocol.java:215)
        at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
        at redis.clients.jedis.Connection.getBinaryMultiBulkReply(Connection.java:276)
        at redis.clients.jedis.BinaryJedis.hgetAll(BinaryJedis.java:1028)
        at org.springframework.data.redis.connection.jedis.JedisHashCommands.hGetAll(JedisHashCommands.java:194)
        ... 29 common frames omitted

@Configuration
    public class RedisConnector {

        private static final Logger LOGGER = LoggerFactory.getLogger(RedisConnector.class);

        /** The host name. */
        @Value("${spring.redis.host}")
        private String hostName;

        /** The port. */
        @Value("${spring.redis.port}")
        private int port;

        /**
         * Jedis connection factory.
         *
         * @return the jedis connection factory
         */
        @Bean
        JedisConnectionFactory jedisConnectionFactory() {

            JedisConnectionFactory jedisConnectionFactory = null;

            try {
                RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(hostName,
                        port);
                jedisConnectionFactory = new JedisConnectionFactory(redisStandaloneConfiguration);
                jedisConnectionFactory.getPoolConfig().setMaxTotal(128);
                jedisConnectionFactory.getPoolConfig().setMaxIdle(128);
            } catch (RedisConnectionFailureException e) {
                LOGGER.error("Connection break with redis " + e.getMessage());
            }

            return jedisConnectionFactory;
        }

        /**
         * Redis template.
         *
         * @return the redis template
         */
        @Bean
        public RedisTemplate<String, Object> redisTemplate() {
            final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
            template.setConnectionFactory(jedisConnectionFactory());
            template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
            template.setEnableTransactionSupport(true);
            return template;
        }

    }
    -------------------------------------------------------------------------
    @Repository
    public class CrowdCountRedisServiceImpl implements ICrowdCountRedisService {

        private static final Logger LOGGER = LoggerFactory.getLogger(CrowdCountRedisServiceImpl.class);

        /** The Constant KEY. */
        private static final String KEY = CrowdCount.class.getName();

        /** The redis template. */
        private RedisTemplate<String, Object> redisTemplate;

        /** The hash operations. */
        private HashOperations<String, Long, CrowdCount> hashOperations;



        /**
         * Instantiates a new crowd count redis service impl.
         *
         * @param redisTemplate the redis template
         */
        @Autowired
        public CrowdCountRedisServiceImpl(RedisTemplate<String, Object> redisTemplate) {
            this.redisTemplate = redisTemplate;
        }

        /**
         * Inits the rest template.
         */
        @PostConstruct
        private void init(){
            hashOperations = redisTemplate.opsForHash();
        }


        @Override
        public void save(CrowdCount crowdCount) {
            LOGGER.info("Inside save method of redis for crowd count");
            if(crowdCount != null){
                hashOperations.put(KEY, crowdCount.getDataStoreId(), crowdCount);
                LOGGER.info("CrowdCount object saved in redis is --------- >"+crowdCount.toString());
            }
            else{
                LOGGER.error("CrowdCount object is null");
            }
        }


        @Override
        public CrowdCount find(Long id) {
            if(id != null){
                return hashOperations.get(KEY, id);
            }else{
                LOGGER.error("Id is missing");
                return null;
            }

        }

        /* (non-Javadoc)
         * @see 
         */
        @Override
        public Map<Long, CrowdCount> findAll() {
            return hashOperations.entries(KEY);
        }


        @Override
        public void update(CrowdCount crowdCount) {
            if(crowdCount != null){
                hashOperations.put(KEY, crowdCount.getDataStoreId(), crowdCount);
            }else{
                LOGGER.error("Object to be updated can not be null");
            }

        }

        @Override
        public void deleteAll() {
            hashOperations.delete(KEY); 

        }

        /* (non-Javadoc)
         * @see 
         */
        @Override
        public void deleteById(Long id) {
            if(id != null){
                hashOperations.delete(KEY, id); 
            }else{
                LOGGER.error("Id can not be null");
            }


        }

    }

So like above service i have multiple services which is interact with redis frequently but after running for few days i end up with above exception so in order resolve the issue ,i have to flush the redis cache and restart the jar which cost lost of data. Configuration:java 8, RedisTemplate with Spring Boot and Jedis 2.9.0
I am really going through hard time to resolve above issue.

@gkorland
Copy link
Contributor

Can you please recheck it with the latest versions of Redis? 2.10.2 or 3.0.1?

@rs10615
Copy link
Author

rs10615 commented Jan 20, 2019

have you used the same version or just suggesting ,i have to make changes in production ,i hope you understand my concern ! have you checked the code i provided above is it fine ?

@sazzad16
Copy link
Collaborator

This is probably a threading issue. I will close this. If you still think it is a bug please reopen it with a reduced piece of code that reproduces this error.

[1] #203 (comment)
[2] #203 (comment)

@vaibhaw-
Copy link

vaibhaw- commented Sep 5, 2019

Ran into a similar issue. Jedis-3.0.0, Redis 5.0.5
Exception trace:

redis.clients.jedis.exceptions.JedisConnectionException: Unknown reply: ↑
at redis.clients.jedis.Protocol.process(Protocol.java:168)
at redis.clients.jedis.Protocol.read(Protocol.java:219)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:309)
at redis.clients.jedis.Connection.getMany(Connection.java:321)
at redis.clients.jedis.Pipeline.sync(Pipeline.java:98)
at redis.clients.jedis.Pipeline.clear(Pipeline.java:84)
at redis.clients.jedis.Pipeline.close(Pipeline.java:157)

Code in question:

            try {
                pipe = jedis.pipelined();
                Response dumpResp = pipe.dump(key);
                Response pttlResp = pipe.pttl(key);
                pipe.sync();
                ....
                ...
            } finally {
                if (pipe != null) {
                    pipe.close(); <<<<<<
                }
            }

Single threaded application that does this operation is a loop. Unable to reproduce as the Redis endpoint is no longer available.

Even if this is due to network issues - is there a way to gracefully handle these errors in close()?

@robertsabo0
Copy link

Same problem. Jedis version: 3.3.0, redis server: 6.0.4
redis.clients.jedis.exceptions.JedisConnectionException: Unknown reply: H
at redis.clients.jedis.Protocol.process(Protocol.java:169)
at redis.clients.jedis.Protocol.read(Protocol.java:220)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:278)
at redis.clients.jedis.Connection.getUnflushedObjectMultiBulkReply(Connection.java:240)
at redis.clients.jedis.JedisPubSub.process(JedisPubSub.java:123)
at redis.clients.jedis.JedisPubSub.proceed(JedisPubSub.java:117)
at redis.clients.jedis.Jedis.subscribe(Jedis.java:2816)
at it.robii.messageorientedcommunication.redis.RedisPubSubComm.subscribe(RedisPubSubComm.java:83)
at it.robii.messageorientedcommunication.Main.testPubSub(Main.java:42)
at it.robii.messageorientedcommunication.Main.TestRedis(Main.java:34)
at it.robii.messageorientedcommunication.Main.main(Main.java:21)

@sazzad16
Copy link
Collaborator

@liz367 You're calling jedis.sync() but you should be calling pipeline.sync()

@liz367
Copy link

liz367 commented Dec 15, 2021

@liz367 You're calling jedis.sync() but you should be calling pipeline.sync()

thanks for your help, i'll have a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants