Use the ingress state updated_at field to ensure that out of order RPC do not overwrite state (#2657)

This commit is contained in:
Benjamin Pracht
2024-04-16 18:10:14 +02:00
committed by GitHub
parent b77f0256c7
commit 6afa63ded3
3 changed files with 14 additions and 6 deletions
+8
View File
@@ -608,6 +608,7 @@ func (s *RedisStore) storeIngressState(_ context.Context, ingressId string, stat
// Use a "transaction" to remove the old room association if it changed
txf := func(tx *redis.Tx) error {
var oldStartedAt int64
var oldUpdatedAt int64
oldState, err := s.loadIngressState(tx, ingressId)
switch err {
@@ -615,6 +616,7 @@ func (s *RedisStore) storeIngressState(_ context.Context, ingressId string, stat
// Ingress state doesn't exist yet
case nil:
oldStartedAt = oldState.StartedAt
oldUpdatedAt = oldState.UpdatedAt
default:
return err
}
@@ -625,6 +627,12 @@ func (s *RedisStore) storeIngressState(_ context.Context, ingressId string, stat
return ingress.ErrIngressOutOfDate
}
if state.StartedAt == oldStartedAt && state.UpdatedAt < oldUpdatedAt {
// Do not overwrite with an old state in case RPCs were delivered out of order.
// All RPCs come from the same ingress server and should thus be on the same clock.
return nil
}
p.Set(s.ctx, IngressStatePrefix+ingressId, data, 0)
return nil