From b4eb169729ab8b5d1e0486ed80791acabfa249a8 Mon Sep 17 00:00:00 2001 From: Andrei Mihu Date: Mon, 15 Aug 2022 14:09:49 +0100 Subject: [PATCH] Faster handling of matches that fail init step. --- server/match_handler.go | 7 ++----- server/runtime_go_match_core.go | 3 +++ server/runtime_javascript_match_core.go | 3 +++ server/runtime_lua_match_core.go | 3 +++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/server/match_handler.go b/server/match_handler.go index a090c1658..e4038c694 100644 --- a/server/match_handler.go +++ b/server/match_handler.go @@ -26,6 +26,8 @@ import ( "go.uber.org/zap" ) +var ErrMatchInitStateNil = errors.New("Match initial state must not be nil") + type MatchDataMessage struct { UserID uuid.UUID SessionID uuid.UUID @@ -131,11 +133,6 @@ func NewMatchHandler(logger *zap.Logger, config Config, sessionRegistry SessionR core.Cleanup() return nil, err } - if state == nil { - core.Cancel() - core.Cleanup() - return nil, errors.New("Match initial state must not be nil") - } // Construct the match. mh := &MatchHandler{ diff --git a/server/runtime_go_match_core.go b/server/runtime_go_match_core.go index b003fdaf2..2090f5355 100644 --- a/server/runtime_go_match_core.go +++ b/server/runtime_go_match_core.go @@ -107,6 +107,9 @@ func (r *RuntimeGoMatchCore) MatchInit(presenceList *MatchPresenceList, deferMes return nil, 0, errors.New("MatchInit returned invalid tick rate, must be between 1 and 60") } r.tickRate = tickRate + if state == nil { + return nil, 0, ErrMatchInitStateNil + } if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, label, r.createTime); err != nil { return nil, 0, err diff --git a/server/runtime_javascript_match_core.go b/server/runtime_javascript_match_core.go index f27144c22..cf858a52d 100644 --- a/server/runtime_javascript_match_core.go +++ b/server/runtime_javascript_match_core.go @@ -230,6 +230,9 @@ func (rm *RuntimeJavaScriptMatchCore) MatchInit(presenceList *MatchPresenceList, if !ok { return nil, 0, errors.New("matchInit is expected to return an object with a 'state' property") } + if state == nil { + return nil, 0, ErrMatchInitStateNil + } if err := rm.matchRegistry.UpdateMatchLabel(rm.id, rm.tickRate, rm.module, label, rm.createTime); err != nil { return nil, 0, err diff --git a/server/runtime_lua_match_core.go b/server/runtime_lua_match_core.go index e068d5dd3..1b4389fb7 100644 --- a/server/runtime_lua_match_core.go +++ b/server/runtime_lua_match_core.go @@ -261,6 +261,9 @@ func (r *RuntimeLuaMatchCore) MatchInit(presenceList *MatchPresenceList, deferMe if state.Type() == LTSentinel { return nil, 0, errors.New("match_init returned unexpected first value, must be a state") } + if state.Type() == lua.LTNil { + return nil, 0, ErrMatchInitStateNil + } r.vm.Pop(1) // Drop the sentinel value from the stack. -- GitLab