microsoft / microsoft/garnet

SSCAN returns incorrect results if items are removed from the set between executions

Open
#1,409 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
12k
Forks
703
Avg merge
2d 19h
Merged PRs (30d)
36

Description

### Describe the bug

If you perform an SSCAN and get a cursor, then remove items from the set, then do another SSCAN using the previously returned cursor you can get incorrect results. It looks like this is because the returned cursor is simply the position in the set for the last entry returned, so if the size of the set changes it refers to the wrong position.

### Steps to reproduce the bug

1. Create a set with 2 entries: `SADD test-set entry-a entry-b`
2. Perform an SSCAN: `SSCAN test-set 0 COUNT 1` - this returns cursor `1`
3. Remove the first entry: `SREM test-set entry-a`
4. Perform another SSCAN using the previously returned cursor: `SSCAN test-set 1 COUNT 1` - this returns no results instead of the expected `entry-b`

### Expected behavior

Using the cursor returned before the set was modified should return the remaining set entries - this is the behaviour in other Redis-like datastores.

### Screenshots

_No response_

### Release version

_No response_

### IDE

_No response_

### OS version

_No response_

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reproducing the issue with the listed SADD, SSCAN, and SREM commands, then trace Garnet's SSCAN handling and cursor state. Done means continuing from the returned cursor after removing entry-a still returns entry-b, with coverage for the reproduction sequence.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, redis
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.