Fetch ignore list before querying for Tickets to fix a race where a ignored ticket could be returned as they move out of ignore list upon assignment
@@ -37,7 +37,7 @@ var (
"app": "openmatch",
"component": "statestore.redis",
})
- mRedisConnLatencyMs = telemetry.HistogramWithBounds("redis/connectlatency", "latency to get a redis connection", "ms", []float64{0, 50, 100, 200, 400, 800, 1600, 3200, 6400})
+ mRedisConnLatencyMs = telemetry.HistogramWithBounds("redis/connectlatency", "latency to get a redis connection", "ms", []float64{0, 50, 200, 500, 1000, 2000, 4000, 10000})
)
type redisBackend struct {
@@ -424,6 +424,18 @@ func (rb *redisBackend) FilterTickets(ctx context.Context, pool *pb.Pool, pageSi
}
defer handleConnectionClose(&redisConn)
+ ttl := rb.cfg.GetDuration("redis.ignoreLists.ttl")
+ curTime := time.Now()
+ curTimeInt := curTime.UnixNano()
+ startTimeInt := curTime.Add(-ttl).UnixNano()
+
+ // Filter out tickets that are fetched but not assigned within ttl time (ms).
+ idsInIgnoreLists, err = redis.Strings(redisConn.Do("ZRANGEBYSCORE", "proposed_ticket_ids", startTimeInt, curTimeInt))
+ if err != nil {
+ redisLogger.WithError(err).Error("failed to get proposed tickets")
+ return status.Errorf(codes.Internal, err.Error())
+ }
+
// A set of playerIds that satisfies all filters
idSet := make([]string, 0)
@@ -447,18 +459,6 @@ func (rb *redisBackend) FilterTickets(ctx context.Context, pool *pb.Pool, pageSi
}
}
- ttl := rb.cfg.GetDuration("redis.ignoreLists.ttl")
- curTime := time.Now()
- curTimeInt := curTime.UnixNano()
- startTimeInt := curTime.Add(-ttl).UnixNano()
-
- // Filter out tickets that are fetched but not assigned within ttl time (ms).
- idsInIgnoreLists, err = redis.Strings(redisConn.Do("ZRANGEBYSCORE", "proposed_ticket_ids", startTimeInt, curTimeInt))
- if err != nil {
- redisLogger.WithError(err).Error("failed to get proposed tickets")
- return status.Errorf(codes.Internal, err.Error())
- }
-
idSet = set.Difference(idSet, idsInIgnoreLists)
// TODO: finish reworking this after the proto changes.
