diff --git a/pkg/server/matchmaker/matchmaker.go b/pkg/server/matchmaker/matchmaker.go index 5a2e04a..e933c1d 100644 --- a/pkg/server/matchmaker/matchmaker.go +++ b/pkg/server/matchmaker/matchmaker.go @@ -119,7 +119,9 @@ func (converge *MatchMaker) Connect(wsProxyMode bool, client, err := converge.admin.AddClient(publicId, conn) cleanUpFunc := func() { - converge.admin.RemoveClient(client) + if client != nil { + converge.admin.RemoveClient(client) + } converge.logStatus() } defer func() { diff --git a/pkg/server/matchmaker/matchmaker_test.go b/pkg/server/matchmaker/matchmaker_test.go index c220042..da3261e 100644 --- a/pkg/server/matchmaker/matchmaker_test.go +++ b/pkg/server/matchmaker/matchmaker_test.go @@ -171,6 +171,14 @@ func (s *MatchMakerTestSuite) Test_singleAgentAndClient() { s.checkState(1, 0) } +func (s *MatchMakerTestSuite) Test_ConnectCLientToUnknownAgent() { + publicId := models.RendezVousId("abc") + + client, err := s.connectClient(publicId) + s.NotNil(err) + s.Nil(client) +} + func (s *MatchMakerTestSuite) Test_multipleAgentsAndClients() { agents := []string{"abc", "def", "ghi"} clients := map[string]int{"abc": 3, "def": 2, "ghi": 5} @@ -232,13 +240,12 @@ func (s *MatchMakerTestSuite) connectClient(publicId models.RendezVousId) (*Test return nil }) - var err error = nil if res[0] != nil { - err = res[0].(error) + return nil, res[0].(error) } client.publicId = publicId client.clientId = clientId - return client, err + return client, nil } func (s *MatchMakerTestSuite) checkState(nAgents int, nClients int) {