fix(multiplayer): fence provider allocation results

This commit is contained in:
Josh Creek
2026-09-03 00:19:03 +01:00
parent a15368ed29
commit bef71e1dcf
5 changed files with 87 additions and 12 deletions
+6 -5
View File
@@ -50,13 +50,14 @@ func (w Worker) RunOnce(ctx context.Context) (bool, error) {
return true, fmt.Errorf("recover provider allocation for match %s: %w", request.MatchID, err)
}
if found {
if err := validateRecoveredAllocation(request, recovered); err != nil {
if err := validateProviderAllocation(request, recovered); err != nil {
return true, fmt.Errorf("recovered provider allocation for match %s: %w", request.MatchID, err)
}
if _, err := w.Service.RecordProviderAllocation(ctx, recovered, w.Now()); err != nil {
recorded, err := w.Service.RecordProviderAllocation(ctx, recovered, w.Now())
if err != nil {
return true, fmt.Errorf("record recovered allocation for match %s: %w", request.MatchID, err)
}
allocation = recovered.Allocation
allocation = recorded
} else {
result, err := w.Service.Allocate(ctx, request, AllocationLabels(request))
if err != nil {
@@ -78,10 +79,10 @@ func (w Worker) RunOnce(ctx context.Context) (bool, error) {
return true, nil
}
func validateRecoveredAllocation(request domain.AllocationRequest, result agones.AllocatedServer) error {
func validateProviderAllocation(request domain.AllocationRequest, result agones.AllocatedServer) error {
allocation := result.Allocation
if result.Endpoint == "" || allocation.State != domain.ServerAllocated || allocation.AllocationID != request.AllocationID || allocation.MatchID != request.MatchID || allocation.ServerID == "" || allocation.Region != request.Region || allocation.Build != request.Build || allocation.Protocol != request.Protocol || allocation.Transport != request.Transport || allocation.ArenaPath != request.ArenaPath {
return fmt.Errorf("recovered allocation does not match request")
return fmt.Errorf("provider allocation does not match request")
}
return nil
}