Skip to content

Commit 4bc099d

Browse files
committed
Fix binary data handling, type safety, and Sentry flood protection
- Pass []byte directly in bytesArgsToInterfaces instead of converting to string - Handle []byte type assertion in argsToBytes for correct Sentry reporting - Fix responseEqual panic when comparing mismatched interface types - Return false in ShouldReport when at capacity to prevent Sentry flooding
1 parent f35c41d commit 4bc099d

4 files changed

Lines changed: 21 additions & 16 deletions

File tree

proxy/compare.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,18 @@ func isConsistent(primaryResp, secondaryResp interface{}, primaryErr, secondaryE
133133

134134
// responseEqual compares two go-redis response values for equality.
135135
func responseEqual(a, b interface{}) bool {
136-
if a == nil && b == nil {
137-
return true
138-
}
139136
if a == nil || b == nil {
140-
return false
141-
}
142-
switch a := a.(type) {
143-
case string, int64:
144-
return a == b
137+
return a == nil && b == nil
138+
}
139+
switch av := a.(type) {
140+
case string:
141+
bv, ok := b.(string)
142+
return ok && av == bv
143+
case int64:
144+
bv, ok := b.(int64)
145+
return ok && av == bv
145146
case []interface{}:
146-
return interfaceSliceEqual(a, b)
147+
return interfaceSliceEqual(av, b)
147148
default:
148149
return reflect.DeepEqual(a, b)
149150
}
@@ -208,7 +209,7 @@ func extractKey(args [][]byte) string {
208209
func bytesArgsToInterfaces(args [][]byte) []interface{} {
209210
out := make([]interface{}, len(args))
210211
for i, a := range args {
211-
out[i] = string(a)
212+
out[i] = a
212213
}
213214
return out
214215
}

proxy/dualwrite.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ func (d *DualWriter) Secondary() Backend {
262262
func argsToBytes(iArgs []interface{}) [][]byte {
263263
out := make([][]byte, len(iArgs))
264264
for i, a := range iArgs {
265-
out[i] = []byte(fmt.Sprintf("%v", a))
265+
if b, ok := a.([]byte); ok {
266+
out[i] = b
267+
} else {
268+
out[i] = []byte(fmt.Sprintf("%v", a))
269+
}
266270
}
267271
return out
268272
}

proxy/proxy_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ func TestBytesArgsToInterfaces(t *testing.T) {
196196
args := [][]byte{[]byte("SET"), []byte("key"), []byte("val")}
197197
result := bytesArgsToInterfaces(args)
198198
assert.Len(t, result, 3)
199-
assert.Equal(t, "SET", result[0])
200-
assert.Equal(t, "key", result[1])
201-
assert.Equal(t, "val", result[2])
199+
assert.Equal(t, []byte("SET"), result[0])
200+
assert.Equal(t, []byte("key"), result[1])
201+
assert.Equal(t, []byte("val"), result[2])
202202
}
203203

204204
func TestResponseEqual(t *testing.T) {

proxy/sentry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ func (r *SentryReporter) ShouldReport(fingerprint string) bool {
103103
delete(r.lastReport, k)
104104
}
105105
}
106-
// If still at capacity after eviction, skip tracking to prevent unbounded growth.
106+
// If still at capacity after eviction, drop report to prevent unbounded growth and Sentry flooding.
107107
if len(r.lastReport) >= maxReportEntries {
108-
return true
108+
return false
109109
}
110110
}
111111

0 commit comments

Comments
 (0)