Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/store/store_valkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ func (vs *valkeyStore) loadSandboxesBySessionIDs(ctx context.Context, sessionIDs
sessionIDKeys = append(sessionIDKeys, vs.sessionKey(sessionID))
}
// MGet should in same slot
stingSliceResults, err := vs.cli.Do(ctx, vs.cli.B().Mget().Key(sessionIDKeys...).Build()).AsStrSlice()
stringSliceResults, err := vs.cli.Do(ctx, vs.cli.B().Mget().Key(sessionIDKeys...).Build()).AsStrSlice()
if err != nil {
return nil, fmt.Errorf("loadSandboxesBySessionIDs: Valkey MGet sandboxes failed: %w", err)
}

if len(stingSliceResults) > len(sessionIDKeys) {
return nil, fmt.Errorf("unexpected MGet result size: %d, param size: %d", len(stingSliceResults), len(sessionIDKeys))
if len(stringSliceResults) > len(sessionIDKeys) {
return nil, fmt.Errorf("unexpected MGet result size: %d, param size: %d", len(stringSliceResults), len(sessionIDKeys))
Comment on lines +119 to +120
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The condition len(stringSliceResults) > len(sessionIDKeys) is insufficient. In Valkey/Redis, the MGET command always returns exactly one result for each key provided, including nil for non-existent keys. Therefore, the length of the result slice should be exactly equal to the number of keys requested. Any discrepancy (either more or fewer results) indicates an unexpected state or protocol error. Using != ensures that the mapping between results and session IDs remains consistent.

Suggested change
if len(stringSliceResults) > len(sessionIDKeys) {
return nil, fmt.Errorf("unexpected MGet result size: %d, param size: %d", len(stringSliceResults), len(sessionIDKeys))
if len(stringSliceResults) != len(sessionIDKeys) {
return nil, fmt.Errorf("unexpected MGet result size: %d, param size: %d", len(stringSliceResults), len(sessionIDKeys))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems sensible, but out of scope of this PR.

}

sandboxResults := make([]*types.SandboxInfo, 0, len(stingSliceResults))
for i, sandboxObjString := range stingSliceResults {
sandboxResults := make([]*types.SandboxInfo, 0, len(stringSliceResults))
for i, sandboxObjString := range stringSliceResults {
if len(sandboxObjString) == 0 {
// sandboxObjString is empty while sessionKey not exist, ignore
continue
Expand Down
Loading