Skip to content

Undefined results when using ReadFrom with SCAN family commands #3287

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

Open
Dishant18 opened this issue May 6, 2025 · 6 comments
Open

Undefined results when using ReadFrom with SCAN family commands #3287

Dishant18 opened this issue May 6, 2025 · 6 comments

Comments

@Dishant18
Copy link

Dishant18 commented May 6, 2025

Bug Report

Current Behavior

We have observed that when using the ReadFrom setting with SCAN family of commands, the continuation requests (with cursor) is not guaranteed to go to the same node as the first request. Due to this behaviour, the results of SCAN family requests are undefined.

We have a master-replica Redis setup with sentinel-based discovery.

Input Code

Input Code
RedisURI redisURI = RedisURI.Builder.sentinel("sentinel-host").build();
RedisClient redisClient = RedisClient.create(redisURI);

StatefulRedisMasterReplicaConnection<byte[], byte[]> conn = MasterReplica.connect(redisClient, ByteArrayCodec.INSTANCE, redisURI);
conn.setReadFrom(ReadFrom.ANY);

byte[] key = getKey();
ScanArgs scanArgs = ScanArgs.Builder.limit(256);
ScanCursor cursor = ScanCursor.INITIAL;
MapScanCursor<byte[], byte[]> resp;
do {
            resp = conn.sync().hscan(key, cursor, scanArgs);
            cursor = ScanCursor.of(hscan.getCursor());
            // Convert and add the results to a map
} while (!resp.isFinished());

Expected behavior/code

SCAN family continuation requests need to be sticky to a Redis Node. When it is used in conjunction with ReadFrom, on every continuation request - a new node can be chosen - which seems like a bug.

Environment

  • Lettuce version(s): 6.4.0.RELEASE
  • Redis version: 7+

Additional Context

The same support is present for ClusterScanCursor. It maintains a nodeId and routes the next command to the same node. Any reason for not adding this in Master-replica setup?

@tishun
Copy link
Collaborator

tishun commented May 7, 2025

Hey @Dishant18 , please allow for the team to catch up with some work after the holidays and we will get back to you.

@shikharid
Copy link
Contributor

@mp911de not contributing anymore?
If it's an oversight, it's a bug which you only can quickly ack and we (me/ @Dishant18 ) might be able to submit a fix.
Less effort for the new team that maintains this and quicker tat for us.

We are writing hacky code at our end to get around this behaviour.

@tishun
Copy link
Collaborator

tishun commented May 7, 2025

@mp911de is always welcome to contribute, but I see he is quite busy with the Spring backlog.

If you and your team have a suggestion how to fix this you are more than welcome to submit a PR.
I'd still have to go over it and verify your solution though, but it shouldn't take much time.

In any case, even if you do not come up with a PR, the team would get to this issue ASAP and let you know how we think we should proceed.

@Dishant18
Copy link
Author

@tishun gentle nudge on this one : )

We are only waiting for you to acknowledge that this is a bug, and we'll submit a PR for this soon. TIA

@Dishant18
Copy link
Author

@tishun gentle nudge again : )
Any updates here will be much appreciated. TIA

@tishun
Copy link
Collaborator

tishun commented May 26, 2025

Hey, apologies for that, I plan to spend some time for this this Friday.

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

No branches or pull requests

3 participants