When LettuceConnectionFactory shareNativeConnection is true, We may encounter serialization failure when querying the value of key1 and returning the value of key2 #3080
Labels
for: external-project
For an external project and not something we can fix
I am using default LettuceConnectionFactory in my springboot webflux project. default field shareNativeConnection is true
image
in some case(maybe high concurrency), when I query key1 from redis, I unexpectedly got the value of key2 Causing serialization failure.
error msg:
[lettuce-epollEventLoop-5-2] [ERROR] c.h.r.c.redisCache - getCacheOrLoadInternal from redis error,key: key1, errMsg: Could not read JSON: Unrecognized token*****##***** expecting (JSON String, Number, Array, Object or token*****##true' or 'false')[N] at [Source: (byte[])"OK"; line: 1, column: 3]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token##***** expecting (JSON String, Number, Array, Object or token*****##*****true' or 'false')[N] at [Source: (byte[])"OK"; line: 1, column: 3]
Expected to obtain a policy model but got OK
[lettuce-epollEventLoop-5-2] [ERROR] c.h.r.c.RedisCache - getCacheOrLoadInternal from redis error, key:key2, errMsg:Could not read JSON: Cannot deserialize value of type java.util.ArrayList<com.test.policy.Policy> from Object value (token*****##Token##ECT)[N] at [Source: (byte[])"{"name":"123","age":16,"address":null,"reversedRelationTypes":null}"; line: 1, column: 1]; nested exception is com.fasterxml.jackson.data##ismatchedInputException: Cannot deserialize value of type java.util.ArrayList<com.test.policy.Policy> from Object value (token##Token#*#*****ECT)[N] at [Source: (byte[])"{"name":"123","age":16,"address":null,"reversedRelationTypes":null}";line: 1, column: 1]
Expected to obtain a policy model but got another model (value of key 3)
this is getCacheOrLoadInternal method
private <T> Mono<T> getCacheOrLoadInternal(String key, RedisSerializationContext<String, T> context, Function<String, Mono<T>> loadingFunction, Duration expireTime) { return redisTemplate.opsForValue(context) .get(key) .timeout(Duration.ofMillis(1000)) .onErrorResume(e -> { log.error("getCacheOrLoadInternal from redis error, key:{}, errMsg:{}", key, e.getLocalizedMessage()); return Mono.empty(); }) .switchIfEmpty(getFromLoadingFunction(key, context, loadingFunction, expireTime)); }
when i set shareNativeConnection is false,There will be no such problem, But it will lead to a waste of resources。
the default value is true, Is this spring-data-redis bug lettuce bug?
this issue is also in spring-projects/spring-data-redis#3077
The text was updated successfully, but these errors were encountered: