redisson icon indicating copy to clipboard operation
redisson copied to clipboard

ClassCastException with Redisson in SpringBoot Application on Frequent Redis Usage

Open guaguaguaxia opened this issue 1 year ago • 8 comments

I am encountering a recurring exception in my SpringBoot application which utilizes Redisson. I open the log level as trace and try to reproduce the problem.The exception trace is as follows:

2023-12-24 20:31:11.741 DEBUG [o2o-xxx-server-xxx,,,] 1 --- [isson-netty-2-4] org.redisson.command.RedisExecutor : connection released for command (MGET) and params [[111, 50, 111, 45, 116, 97, 107, 101, 111, 117, ...]] from slot NodeSource [slot=0, addr=null, redisClient=null, redirect=null, entry=null] using connection RedisConnection@1435186242 [redisClient=[addr=redis://redis.xxx.com:6379], channel=[id: 0xfbca5b0c, L:/172.20.xx.xx:45622 - R:redis.xxx.com/192.168.12.xx:6379], currentCommand=CommandData [promise=java.util.concurrent.CompletableFuture@72648364[Completed normally], command=(MGET), params=[[111, 50, 111, 45, 116, 97, 107, 101, 111, 117, ...]], codec=org.redisson.client.codec.ByteArrayCodec], usage=-1] java.util.concurrent.CompletionException: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273) at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280) at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1643) 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: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List at org.redisson.spring.data.connection.RedissonConnection.mGet(RedissonConnection.java:491) at org.springframework.data.redis.connection.DefaultStringRedisConnection.mGet(DefaultStringRedisConnection.java:766) at org.springframework.data.redis.core.DefaultValueOperations.lambda$multiGet$7(DefaultValueOperations.java:180) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:228) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:188) at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:96) at org.springframework.data.redis.core.DefaultValueOperations.multiGet(DefaultValueOperations.java:180) at dev.memestudio.framework.redis.RedisOps.mGet(RedisOps.java:106) at dev.memestudio.framework.redis.RedisOps.mGet(RedisOps.java:102)

After a long period of observation,This issue seems to manifest under certain consistent patterns:

  1. Temporary Resolution by Restart: Whenever this error occurs, restarting the service temporarily resolves the issue.

  2. Frequency and Duration: The application runs fine for a period, but then this error starts appearing. The onset of the error seems related to the frequency of Redis usage - the more frequent the Redis interaction, the sooner the error appears.

  3. Connection Pool Size: Increasing the Redisson client's connection thread pool size (the parameter ConnectPoolSize) delays the onset of this error, but does not permanently resolve it.

I have tried to ensure that the data types used with the all method are correct and consistent. However, the issue persists. I am looking for advice or solutions to permanently resolve this error. Any insights or suggestions would be greatly appreciated.

Thank you in advance for your assistance.

guaguaguaxia avatar Dec 24 '23 13:12 guaguaguaxia

Which Redisson version?

mrniko avatar Dec 25 '23 12:12 mrniko

3.17.4

guaguaguaxia avatar Dec 25 '23 14:12 guaguaguaxia

and config Config config = new Config(); SingleServerConfig singleServerConfig = config.useSingleServer(); singleServerConfig.setAddress("redis://" + properties.getHost() + ":" + properties.getPort()); singleServerConfig.setPassword(properties.getPassword()); singleServerConfig.setTimeout(60000); singleServerConfig.setConnectTimeout(30000);

guaguaguaxia avatar Dec 25 '23 14:12 guaguaguaxia

Try 3.19.2 version or higher.

mrniko avatar Dec 26 '23 06:12 mrniko

Could you please confirm if this issue was specifically addressed and resolved in version 3.19.2? We are concerned about the potential risks and costs associated with updating versions, so we want to be sure before proceeding.

guaguaguaxia avatar Dec 26 '23 08:12 guaguaguaxia

3.19.2 fixed the issue - command replies don't match if exception is thrown in CommandEncoder

mrniko avatar Dec 26 '23 09:12 mrniko

It doesn't seem to be this error. My Redis instance is provided by a cloud service provider and supports 10,000 connections. Currently, I am only using 1,000 connections. Moreover, the cloud service provider ensures stable operation of the instance, so it shouldn't be experiencing frequent errors like it is now. Of course, I will try various methods to resolve this issue. If I find a solution, I will update here. Thank you for your assistance.

guaguaguaxia avatar Dec 27 '23 08:12 guaguaguaxia

here is the similar issue https://github.com/redisson/redisson/issues/5227. PTAL Upgrade to 3.23.2 resolved the issue.

mrniko avatar Dec 27 '23 12:12 mrniko