Skip to content

Exception when there are multiple connectional approval callbacks #1941

Closed
@jlao

Description

@jlao

Description

If you register multiple connectional approval callbacks on NetworkManager.Singleton.ConnectionApprovalCallback, then you will get an exception because NetworkManager.HandleApproval will be invoked twice for the same client. An exception is thrown when trying to add the client multiple times to m_ConnectedClients.

ArgumentException: An item with the same key has already been added. Key: 0
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <cc07565d1e884982b04875f1b674afb1>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <cc07565d1e884982b04875f1b674afb1>:0)
Unity.Netcode.NetworkManager.HandleApproval (System.UInt64 ownerClientId, System.Boolean createPlayerObject, System.Nullable`1[T] playerPrefabHash, System.Boolean approved, System.Nullable`1[T] position, System.Nullable`1[T] rotation) (at /Users/james.lao/Code/com.unity.netcode.gameobjects/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs:1828)

Reproduce Steps

  1. Register more than one connection approval callback that all approve the connection.
  2. Start as host.

Actual Outcome

An exception is thrown when trying to .Add() the client to the m_ConnectedClients dictionary.

Expected Outcome

Either disallow multiple connection approval callbacks or handle it correctly.

Screenshots

n/a

Environment

  • OS: macOS Monterey Big Sur
  • Unity Version: 2021.15f1
  • Netcode Version: latest from develop branch
  • Netcode Commit: b8b6dfc

Additional Context

n/a

Metadata

Metadata

Assignees

Labels

stat:importStatus - Issue is going to be saved internallytype:bugBug Report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions