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 #3077

Closed
swh624083440 opened this issue Dec 16, 2024 · 7 comments
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged

Comments

@swh624083440
Copy link

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?

@mp911de
Copy link
Member

mp911de commented Dec 16, 2024

Thanks for the report.
If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal yet complete sample that reproduces the problem.
You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Without a reproducer, we can't find out what is happening here. It could be that some responses get out of order with Lettuce. Spring Data Redis uses byte[] and an own deserializer (not Lettuce's RedisCodec).

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Dec 16, 2024
@swh624083440
Copy link
Author

swh624083440 commented Dec 16, 2024

my redis config
image

getCache
image

RedisSerializationContext
image

use
image

Extremely occasional scenes occur

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 16, 2024
@mp911de
Copy link
Member

mp911de commented Dec 16, 2024

We need a runnable reproducer, a collection of screenshots is unusable for us.

@mp911de mp911de added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Dec 16, 2024
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Dec 23, 2024
@swh624083440
Copy link
Author

My Redis configuration is as shown in the screenshot above. As it is a very occasional operation (suspected to be in a high concurrency scenario), I have provided a demo example, but it may not be reproducible. Therefore, I have provided a screenshot.
My solution is to set shareNativeConnection as false.
Therefore, I would like to confirm if the above issue may occur if set shareNativeConnection is true

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Dec 25, 2024
@swh624083440
Copy link
Author

The above problem may occur after a period of time after the occurrence of OOM

@mp911de
Copy link
Member

mp911de commented Jan 7, 2025

The above problem may occur after a period of time after the occurrence of OOM

This is an interesting data point. I'm going to provide these details to the Lettuce maintainers at redis/lettuce#3117.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants