envoyproxy / envoyproxy/envoy

Envoy Redis proxy SCAN implementation not compatible with Redis specification

Open
#42,889 3 comments 3 reactions 0 assignees View on GitHub
area/redis bug help wanted
Dominant language
C++
Stars
28.9k
Forks
5.6k
Avg merge
1d 20h
Merged PRs (30d)
428

Description

*Title*: *Envoy Redis proxy SCAN implementation not compatible with Redis specification*

*Description*:
When using the `SCAN` command through Envoy's Redis proxy against a Redis cluster, Envoy fans out the SCAN request to all Redis masters and returns concatenated responses. According to the Redis specification, `SCAN` return value is an array of two values: the first value is the new cursor to use in the next call, the second value is an array of elements. However, Envoy returns multiple cursor/keys pairs (one per master).

Expected result:
```shell
1) "288"
2) 1) "test:key:895"
2) "test:key:565"
3) "test:key:963"
4) "test:key:330"
5) "test:key:457"
```

Actual result (when cluster has 3 masters):
```shell
1) "133"
2) 1) "test:key:248"
2) "test:key:57"
3) "test:key:116"
4) "test:key:191"
5) "test:key:514"
3) "277"
4) 1) "test:key:942"
2) "test:key:982"
3) "test:key:995"
4) "test:key:567"
5) "test:key:812"
5) "69"
6) 1) "test:key:859"
2) "test:key:224"
3) "test:key:543"
4) "test:key:542"
5) "test:key:621"
```

SCAN cursors are instance-specific, i.e., each cursor is only valid for the Redis instance that generated it. When Envoy fans out SCAN to all masters and returns multiple cursor/keys pairs, cursors from different masters are mixed, with no way to identify which cursor belongs to which master. This makes it impossible to reliably continue scanning, as there's no way to match cursors to their originating masters across requests. As a result, `SCAN` through Envoy's Redis proxy cannot reliably scan the keyspace, leading to unpredictable behavior, resource exhaustion, or incomplete scans.

*Relevant Links*:
- [Redis SCAN command spec](https://redis.io/docs/latest/commands/scan/)
- [Envoy SCAN implementation PR](https://github.com/envoyproxy/envoy/pull/39702)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.