mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
fix(multiplayer): reconcile authoritative initial connections
This commit is contained in:
@@ -134,6 +134,7 @@ func newAPIService(db *sql.DB, workloadSecret string, indexes ...api.CandidateIn
|
||||
ProposalPromoter: api.ProposalPromoterFromStore(db),
|
||||
ServerRegistrar: api.ServerRegistrarFromStore(db),
|
||||
ServerShutdowner: api.ServerShutdownerFromStore(db),
|
||||
ServerConnections: api.ServerConnectionsFromStore(db),
|
||||
ResultSubmitter: store.PostgresResults{DB: db},
|
||||
RankedProfileProvider: store.PostgresRankedProfiles{DB: db},
|
||||
TierPolicy: domain.DefaultTierPolicy(),
|
||||
|
||||
@@ -39,6 +39,7 @@ func main() {
|
||||
sdkBaseURL := options.String("sdk-base-url", "", "Agones SDK REST base URL; empty enables direct mode")
|
||||
readyURL := options.String("ready-url", "", "explicit process-ready probe URL")
|
||||
drainURL := options.String("drain-url", "", "loopback drain URL")
|
||||
admissionURL := options.String("initial-connect-ready-url", "", "authenticated loopback URL that starts the initial-connect clock after durable assignment readiness")
|
||||
drainTokenEnv := options.String("drain-token-env", "COSMIC_CLASH_DRAIN_TOKEN", "environment variable containing the drain bearer token")
|
||||
transport := options.String("transport", "enet", "enet or steam_sdr")
|
||||
grace := options.Duration("drain-grace", supervisor.DefaultDrainGrace, "maximum graceful drain duration")
|
||||
@@ -64,6 +65,7 @@ func main() {
|
||||
SDKBaseURL: *sdkBaseURL,
|
||||
ReadyURL: *readyURL,
|
||||
DrainURL: *drainURL,
|
||||
AdmissionURL: *admissionURL,
|
||||
DrainToken: token,
|
||||
Transport: *transport,
|
||||
ReadyTimeout: 30 * time.Second,
|
||||
|
||||
@@ -20,6 +20,7 @@ func main() {
|
||||
dsn := flag.String("dsn", os.Getenv("COSMIC_CLASH_POSTGRES_DSN"), "PostgreSQL connection string")
|
||||
migrationDir := flag.String("migrations", "migrations", "directory containing numbered SQL migrations")
|
||||
interval := flag.Duration("interval", time.Minute, "maintenance poll interval")
|
||||
initialConnectInterval := flag.Duration("initial-connect-interval", time.Second, "initial-connect reconciliation poll interval")
|
||||
batch := flag.Int("batch", 100, "maximum player rollovers per pass")
|
||||
stalledAllocationDeadline := flag.Duration("stalled-allocation-deadline", 2*time.Minute, "reclaim a match stuck in ALLOCATING/PROCESS_READY/ASSIGNMENT_READY (server crashed or was reclaimed before registering) after this long, requeuing every participant without penalty")
|
||||
stalledAllocationBatch := flag.Int("stalled-allocation-batch", 100, "maximum stalled matches reclaimed per pass")
|
||||
@@ -28,7 +29,7 @@ func main() {
|
||||
if *dsn == "" {
|
||||
fatalf("--dsn or COSMIC_CLASH_POSTGRES_DSN is required")
|
||||
}
|
||||
if *interval <= 0 || *batch < 1 || *batch > 1000 {
|
||||
if *interval <= 0 || *initialConnectInterval <= 0 || *batch < 1 || *batch > 1000 {
|
||||
fatalf("invalid interval or batch")
|
||||
}
|
||||
if *stalledAllocationDeadline <= 0 || *stalledAllocationBatch < 1 || *stalledAllocationBatch > 1000 {
|
||||
@@ -52,8 +53,7 @@ func main() {
|
||||
}
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
for {
|
||||
now := time.Now().UTC()
|
||||
runGeneral := func(now time.Time) {
|
||||
count, err := store.RolloverDueSeasons(ctx, db, now, *batch)
|
||||
if err != nil {
|
||||
fatalf("season maintenance: %v", err)
|
||||
@@ -68,6 +68,8 @@ func main() {
|
||||
if reclaimed > 0 {
|
||||
log.Printf("reclaimed %d stalled allocations, requeuing their participants", reclaimed)
|
||||
}
|
||||
}
|
||||
runInitialConnect := func(now time.Time) {
|
||||
reconciled, err := store.ReconcileInitialConnect(ctx, db, now, *initialConnectBatch)
|
||||
if err != nil {
|
||||
fatalf("initial-connect maintenance: %v", err)
|
||||
@@ -75,12 +77,22 @@ func main() {
|
||||
if reconciled > 0 {
|
||||
log.Printf("reconciled %d initial-connect outcomes", reconciled)
|
||||
}
|
||||
timer := time.NewTimer(*interval)
|
||||
}
|
||||
|
||||
runGeneral(time.Now().UTC())
|
||||
runInitialConnect(time.Now().UTC())
|
||||
generalTicker := time.NewTicker(*interval)
|
||||
initialConnectTicker := time.NewTicker(*initialConnectInterval)
|
||||
defer generalTicker.Stop()
|
||||
defer initialConnectTicker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
timer.Stop()
|
||||
return
|
||||
case <-timer.C:
|
||||
case now := <-generalTicker.C:
|
||||
runGeneral(now.UTC())
|
||||
case now := <-initialConnectTicker.C:
|
||||
runInitialConnect(now.UTC())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ func main() {
|
||||
ProposalPromoter: api.ProposalPromoterFromStore(db),
|
||||
ServerRegistrar: api.ServerRegistrarFromStore(db),
|
||||
ServerShutdowner: api.ServerShutdownerFromStore(db),
|
||||
ServerConnections: api.ServerConnectionsFromStore(db),
|
||||
ResultSubmitter: store.PostgresResults{DB: db},
|
||||
RankedProfileProvider: store.PostgresRankedProfiles{DB: db},
|
||||
TierPolicy: domain.DefaultTierPolicy(),
|
||||
|
||||
Reference in New Issue
Block a user