Commit 677f58c0 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Cancel Lua runtime context when authoritative match fails to start.

parent 0fb1e182
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -4,8 +4,12 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http://keepachangelog.com) and this project uses [semantic versioning](http://semver.org).

## [Unreleased]
### Added
- Make authoritative match join attempt marker deadline configurable.

### Fixed
- Correctly register deferred messages sent from authoritative matches.
- Correctly cancel Lua authoritative match context when match initialization fails.

## [2.3.0] - 2018-12-31
### Added
+5 −0
Original line number Diff line number Diff line
@@ -148,6 +148,9 @@ func ParseArgs(logger *zap.Logger, args []string) Config {
	if mainConfig.GetMatch().DeferredQueueSize < 1 {
		logger.Fatal("Match deferred queue size must be >= 1", zap.Int("match.deferred_queue_size", mainConfig.GetMatch().DeferredQueueSize))
	}
	if mainConfig.GetMatch().JoinMarkerDeadlineMs < 1 {
		logger.Fatal("Match join marker deadline must be >= 1", zap.Int("match.join_marker_deadline_ms", mainConfig.GetMatch().JoinMarkerDeadlineMs))
	}
	if mainConfig.GetTracker().EventQueueSize < 1 {
		logger.Fatal("Tracker presence event queue size must be >= 1", zap.Int("tracker.event_queue_size", mainConfig.GetTracker().EventQueueSize))
	}
@@ -488,6 +491,7 @@ type MatchConfig struct {
	CallQueueSize        int `yaml:"call_queue_size" json:"call_queue_size" usage:"Size of the authoritative match buffer that sequences calls to match handler callbacks to ensure no overlaps. Default 128."`
	JoinAttemptQueueSize int `yaml:"join_attempt_queue_size" json:"join_attempt_queue_size" usage:"Size of the authoritative match buffer that limits the number of in-progress join attempts. Default 128."`
	DeferredQueueSize    int `yaml:"deferred_queue_size" json:"deferred_queue_size" usage:"Size of the authoritative match buffer that holds deferred message broadcasts until the end of each loop execution. Default 128."`
	JoinMarkerDeadlineMs int `yaml:"join_marker_deadline_ms" json:"join_marker_deadline_ms" usage:"Deadline in milliseconds that client authoritative match joins will wait for match handlers to acknowledge joins. Default 5000."`
}

// NewMatchConfig creates a new MatchConfig struct.
@@ -497,6 +501,7 @@ func NewMatchConfig() *MatchConfig {
		CallQueueSize:        128,
		JoinAttemptQueueSize: 128,
		DeferredQueueSize:    128,
		JoinMarkerDeadlineMs: 5000,
	}
}

+3 −3
Original line number Diff line number Diff line
@@ -49,16 +49,16 @@ type RankMap struct {
	SortOrder int
}

func (r RankMap) Len() int {
func (r *RankMap) Len() int {
	return len(r.Ranks)
}
func (r RankMap) Swap(i, j int) {
func (r *RankMap) Swap(i, j int) {
	rank1 := r.Ranks[i]
	rank2 := r.Ranks[j]
	r.Ranks[i], r.Ranks[j] = rank2, rank1
	rank1.Rank, rank2.Rank = rank2.Rank, rank1.Rank
}
func (r RankMap) Less(i, j int) bool {
func (r *RankMap) Less(i, j int) bool {
	rank1 := r.Ranks[i]
	rank2 := r.Ranks[j]
	if r.SortOrder == LeaderboardSortOrderDescending {
+6 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ package server

import (
	"github.com/gofrs/uuid"
	"go.uber.org/atomic"
	"sync"
)

@@ -52,6 +53,7 @@ func (p *MatchPresence) GetStatus() string {
// Used to monitor when match presences begin and complete their match join process.
type MatchJoinMarker struct {
	expiryTick int64
	marked     *atomic.Bool
	ch         chan struct{}
}

@@ -64,6 +66,7 @@ func (m *MatchJoinMarkerList) Add(sessionID uuid.UUID, expiryTick int64) {
	m.Lock()
	m.joinMarkers[sessionID] = &MatchJoinMarker{
		expiryTick: expiryTick,
		marked:     atomic.NewBool(false),
		ch:         make(chan struct{}),
	}
	m.Unlock()
@@ -82,8 +85,10 @@ func (m *MatchJoinMarkerList) Get(sessionID uuid.UUID) <-chan struct{} {
func (m *MatchJoinMarkerList) Mark(sessionID uuid.UUID) {
	m.RLock()
	if joinMarker, ok := m.joinMarkers[sessionID]; ok {
		if joinMarker.marked.CAS(false, true) {
			close(joinMarker.ch)
		}
	}
	m.RUnlock()
}

+2 −6
Original line number Diff line number Diff line
@@ -207,16 +207,12 @@ func (p *Pipeline) matchJoin(logger *zap.Logger, session Session, envelope *rtap
		}
		if mode == StreamModeMatchAuthoritative {
			// If we've reached here, it was an accepted authoritative join.
			ctx, ctxCancelFn := context.WithTimeout(session.Context(), 5*time.Second)
			ctx, ctxCancelFn := context.WithTimeout(session.Context(), time.Duration(p.config.GetMatch().JoinMarkerDeadlineMs)*time.Millisecond)
			if err := p.matchRegistry.AwaitJoinMarker(ctx, matchID, node, session.ID(), p.node); err != nil {
				if err != context.Canceled {
					ctxCancelFn()
				}
				// There was an error or a timeout waiting for the join marker, return to the client anyway since the tracker update was successful.
				logger.Error("Error waiting for match join marker", zap.Error(err))
			} else {
				ctxCancelFn()
			}
			ctxCancelFn()
			label = &wrappers.StringValue{Value: l}
		}
		meta = &m
Loading