WebGL/WSS: Error: Abnormal disconnection after having isMessageQueueRunning = false for ~16 seconds

Try it yourself: http://trail-demos.s3.amazonaws.com/photonbug/index.html

Using PUN v1.90 and Unity 2017.4. There is one simple Script running:
    public IEnumerator PrintState() {
        ClientState lastState = ClientState.Uninitialized;
        while (true) {
            var state = PhotonNetwork.connectionStateDetailed;
            if (state != lastState) {
                Debug.Log("detailed state change: " + state);
            }
            lastState = state;
            yield return null;
        }
    }

    public IEnumerator PrintSimpleState() {
        ConnectionState lastState = ConnectionState.Disconnected;
        while (true) {
            var state = PhotonNetwork.connectionState;
            if (state != lastState) {
                Debug.Log("simple state change: " + state);
            }
            lastState = state;
            yield return null;
        }
    }

    public void Awake() {
        StartCoroutine(PrintState());
        StartCoroutine(PrintSimpleState());
    }

    public void Start () {
        PhotonNetwork.ConnectUsingSettings(null);
    }

    public void OnJoinedLobby() {
        PhotonNetwork.CreateRoom("a room");
    }

    public void OnJoinedRoom() {
        Debug.Log("setting PhotonNetwork.isMessageQueueRunning = false");
        PhotonNetwork.isMessageQueueRunning = false;
    }

Comments

  • Hi @hpohl,

    if you set PhotonNetwork.isMessageQueueRunning to false, you will stop sending data to the server. If the server does not receive any data from a certain client in a certain amount of time (should be around 10 seconds), the server will disconnect the client. This is not a problem for most likely all of the supported platform, except for WebGL.

    When the Message Queue gets enabled for the first time, there is also a thread being started to send ACKs to the server preventing from disconnects. Those ACKs are also sent if the Message Queue gets disabled in order to keep the connection alive. Since WebGL does not allow threads, there is no fallback thread started which means, that the client does not send any ACKs to the server. If you now disable the Message Queue and the client stops sending data to the server, the client gets disconnected after a certain amount of time.
  • Hi Christian,

    thank you for the answer.

    Makes sense. And sending these ACKs manually when using WebSockets is not supported?
  • This doesn't depend on the usage of WebSockets, it's about the usage of WebGL. For example using Windows as target platform with WebSockets, shouldn't be a problem for this scenario, because a fallback thread is started automatically to send ACKs. For WebGL builds you would have to use another solution, because threads are not supported. You could workaround this using a Coroutine which sends regularly ACKs to the server. To do this you can use PhotonNetwork.networkingPeer.SendAcksOnly(); inside a Coroutine, which gets started when you disable the Message Queue and ends when you enable the Message Queue again.
  • Worked beautifully, thank you :)
Sign In or Register to comment.