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

When LettuceConnectionFactory shareNativeConnection is true, We may encounter serialization failure when querying the value of key1 and returning the value of key2 #3080

Closed
swh624083440 opened this issue Dec 16, 2024 · 1 comment
Labels
for: external-project For an external project and not something we can fix

Comments

@swh624083440
Copy link

swh624083440 commented Dec 16, 2024

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

@mp911de
Copy link
Collaborator

mp911de commented Dec 16, 2024

RedisCache and RedisSerializationContext are Spring Data Redis classes.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2024
@mp911de mp911de added the for: external-project For an external project and not something we can fix label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

2 participants