SecurityExceptionOnConnect

Hello everyone,

I' m working on a multiplayer game played with unity3d web player. The game is hosted on Amazon EC2 and using Photon Cloud. Everything works fine but sometimes the player crashes as well as unity editor because of a SecurityExceptionOnConnect exception. I looked for a solution on the forums but couldn' t find any solution.

I allowed TCP-843 port on security group of my EC2, i have a valid crossdomain.xml file on the server. the strange thing is this problem occurs sometimes not depending on a particular situation. It' s just happen.

Below you can see the exception message on the console of mac os x:

Received unknown status code: SecurityExceptionOnConnect
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:LogError(Object)
PhotonHandler:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:158)
NetworkingPeer:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:716)
NetworkingPeer:OnStatusChanged(StatusCode) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1158)
ExitGames.Client.Photon.NConnect:StartConnection()
ExitGames.Client.Photon.EnetPeer:Connect(String, String, Byte)
ExitGames.Client.Photon.PhotonPeer:Connect(String, String)
NetworkingPeer:Connect(String, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:166)
NetworkingPeer:OnStatusChanged(StatusCode) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1043)
ExitGames.Client.Photon.NConnect:StartConnection()
ExitGames.Client.Photon.EnetPeer:Connect(String, String, Byte)
ExitGames.Client.Photon.PhotonPeer:Connect(String, String)
NetworkingPeer:Connect(String, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:166)
NetworkingPeer:OnStatusChanged(StatusCode) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1043)
ExitGames.Client.Photon.NConnect:StartConnection()
ExitGames.Client.Photon.EnetPeer:Connect(String, String, Byte)
ExitGames.Client.Photon.PhotonPeer:Connect(String, String)
NetworkingPeer:Connect(String, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:166)
NetworkingPeer:OnStatusChanged(StatusCode) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1043)
ExitGames.Client.Photon.NConnect:StartConnection()
ExitGames.Client.Photon.EnetPeer:Connect(String, String, Byte)
ExitGames.Client.Photon.PhotonPeer:Connect(String, String)
NetworkingPeer:Connect(String, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:166)
NetworkingPeer:OnStatusChanged(StatusCode) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1043)
ExitGames.Client.Photon.EnetPeer:Disconnected()
ExitGames.Client.Photon.NConnect:<Run>b__1()
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:65)


Game starts to throw this exception and continue until the application is killed.

Thanks.

Comments

  • Security exception means that you failed to establish the security of Photon itself.
    One side likely establishes it (client or master client / server) while the other side doesn't.

    This has nothing to do with webplayer crossdomain security.
  • I debugged the program. It seems it' s entering an infinite loop between NetworkingPeer.OnStatusChanged and connect. As state SecurityExceptionOnConnect comes as parameter to OnStatusChanged but it' s not handled in the switch-case statement so code throws a debugError which says unknown exception. After trying several times in OnStatusChanged again code enters Status.Disconnect but Connect function called there so it' s starting an infinite loop
  • Ouch. Good find. Sorry for that!
    I could reproduce this if the master's policy allows a connect, while the game server's don't.

    This case is a bit tricky to solve. I'll upload a fixed version soon.
    If you want to fix this asap, do the following:
    - In NetworkingPeer.OnStatusChanged find case StatusCode.Disconnect. The Connect() calls should only modify the state if Connect returns true. Otherwise, keep the state.
    - In NetworkingPeer.OnStatusChanged find case StatusCode.ExceptionOnConnect. Above that line, add the "case SecurityExceptionOnConnect:". Without a break (using the same resolution).
    - Implement OnFailedToConnectToPhoton if you wanted to. After the modifications, this is called when the policy wasn't available.

    I also added one value to the enum DisconnectCause:
    /// <summary>The security settings for client or server don't allow a connection (see remarks).</summary>
    /// <remarks>
    /// A common cause for this is that browser clients read a "crossdomain" file from the server.
    /// If that file is unavailable or not configured to let the client connect, this exception is thrown.
    /// Photon usually provides this crossdomain file for Unity.
    /// If it fails, read:
    /// http://doc.exitgames.com/photon-server/PolicyApp
    /// </remarks>
    SecurityExceptionOnConnect = StatusCode.SecurityExceptionOnConnect,
  • I' ll have my vengeance from you cause i lost too many players because of that.

    Just kidding:D

    Thanks, can you update this post when you fix the problem
  • Bah, mean joke! :lol:
    Just updated my post above with a solution. As said, I'll update PUN soon but I don't know if it maybe takes a day or two.
  • I really appriciated for the solution. Because my game is on the test and players were really complaining.

    anyway, thanks again