Mirror icon indicating copy to clipboard operation
Mirror copied to clipboard

[Server] attribute race condition above OnStartServer, on NetworkAuthenticator.

Open JesusLuvsYooh opened this issue 3 years ago • 1 comments

Describe the bug [Server] attribute above OnStartServer, on NetworkAuthenticator stops it being called.

[IMPORTANT] How can we reproduce the issue, step by step: Create a public class CustomNetworkAuthenticator : NetworkAuthenticator Script template version is ideal. Add [Server] above OnStartServer. You get a yellow warning "[Server] function 'System.Void CustomNetworkAuthenticator::OnStartServer()' called when server was not active"

[Server]
public override void OnStartServer()
{
        Debug.Log("1 OnStartServer : " + gameObject.name);
        // register a handler for the authentication request we expect from client
        NetworkServer.RegisterHandler<AuthRequestMessage>(OnAuthRequestMessage, false);
}

FYI, none of the script templates show or say to add the Server tag, so shouldn't happen often to users. [Server] above OnStartServer in a custom NetworkManager works fine.

JesusLuvsYooh avatar Jun 15 '22 07:06 JesusLuvsYooh

Good catch. This happens because the listening happens after the execution of OnStartServer.

https://github.com/vis2k/Mirror/blob/db50c39b918d42b21eb9d0b24319e8ca75f30d19/Assets/Mirror/Runtime/NetworkManager.cs#L244-L263

MaZyGer avatar Jun 16 '22 01:06 MaZyGer

Closing per comments above...tag should not be added.

MrGadget1024 avatar Nov 24 '22 12:11 MrGadget1024