Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

NetworkMessage from UNET WebGL client crashes server (even in editor)

Discussion in 'UNet' started by ikefrc, Dec 26, 2015.

  1. ikefrc

    ikefrc

    Joined:
    Jul 3, 2012
    Posts:
    81
    I have two separate projects (UNET client & UNET server). When I run the client from editor, there are no issues. However when I deploy to WebGL a particular NetworkMessage, which works without issues in editor, crashes the server (no error on client).

    The NetworkMessage is a png decoded to byte[] and send over a ReliableFragmented channel.

    Network config:

    Code (csharp):
    1. ConnectionConfig config = new ConnectionConfig();
    2. config.AddChannel(QosType.Reliable);
    3. config.AddChannel(QosType.ReliableFragmented);
    4. config.AddChannel(QosType.Unreliable);
    5. config.MaxSentMessageQueueSize = 128;
    6. NetworkServer.Configure(config, 100);
    7. NetworkServer.useWebSockets = true;
    8. NetworkServer.Listen(19019);
    9. NetworkServer.RegisterHandler(UPLOAD_FILE, OnUploadFile);
    The server crashes instantly after showing the red error message (quick screengrab):



    This always happens when the message comes from webgl clients, no issue when it comes from editor clients.

    Where it crashes
    Code (csharp):
    1.  
    2. void OnUploadFile(NetworkMessage msg)
    3. {
    4.         FileMessage wmsg = msg.ReadMessage<FileMessage>();
    5.         print(wmsg.data.Length);
    6.         //CRASH HAPPENS HERE
    7.  
    8. }
    9.  
     
  2. ikefrc

    ikefrc

    Joined:
    Jul 3, 2012
    Posts:
    81
    Here is a more in-depth error log

    This is where in happens inside Networking.NetworkIdentity
    Code (csharp):
    1.  
    2. else
    3. {
    4. //NOTE: this throws away the rest of the buffer. Need moar error codes
    5. if (LogFilter.logError) { Debug.LogError("Unknown message ID " + msgType + " connId:" + connectionId); }
    6. break;
    7. }
    8.  
     
  3. ikefrc

    ikefrc

    Joined:
    Jul 3, 2012
    Posts:
    81
    Logging the Messages I noticed the following:
    1212 and 1223 are valid message type ids. -25580 isn't.
    Looks like some sort of weird error where when long messages are fragmented, the msgID gets messed up and crashes the server.
     
  4. ikefrc

    ikefrc

    Joined:
    Jul 3, 2012
    Posts:
    81
    I've created sample projects (client & server) of this reproducible crash and uploaded a bug report #760104.
     
  5. ikefrc

    ikefrc

    Joined:
    Jul 3, 2012
    Posts:
    81
    So, any feedback from the Unity devs here? The crash is still happening as of 5.3.2f1.
    This is a severe bug as it would be trivial to build a client which can crash any server using UNETs Hight-Level API.
     
  6. Morgenstern_1

    Morgenstern_1

    Joined:
    Jul 1, 2013
    Posts:
    34
    I'm seeing the same issue in a non-webGL build. Occasionally getting errors that read:

    Unknown message ID -21808 connId:1
    UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:LogError(Object)
    UnityEngine.Networking.NetworkConnection:HandleReader(NetworkReader, Int32, Int32) (at C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:466)
    UnityEngine.Networking.NetworkConnection:HandleBytes(Byte[], Int32, Int32) (at C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:386)
    UnityEngine.Networking.NetworkConnection:TransportRecieve(Byte[], Int32, Int32) (at C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:536)
    UnityEngine.Networking.NetworkClient:Update() (at C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkClient.cs:648)
    UnityEngine.Networking.NetworkClient:UpdateClients() (at C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkClient.cs:861)
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate() (at C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkIdentity.cs:1059)

    The message ID is varying, but there's nothing in my code that would send a message with a negative ID. Not sure how to approach this one.
     
  7. ikefrc

    ikefrc

    Joined:
    Jul 3, 2012
    Posts:
    81
    There isn't much to approach unfortunately, I've dug around in the networking source and posted some information above, even uploaded a reproducible project 3 months ago, but so far the bug report has been untouched.

    Do you have any long fragmented messages in use? I think one fragment somehow overflow into the next packet and therefore starting bits of data are picked up as the id (hence random even negative id).
     
  8. Morgenstern_1

    Morgenstern_1

    Joined:
    Jul 1, 2013
    Posts:
    34
    We're not using any fragmented messages at the moment, we're mostly sending lots of smaller messages. The only channels currently in use are Reliable Sequenced and Reliable State Update.
     
  9. Morgenstern_1

    Morgenstern_1

    Joined:
    Jul 1, 2013
    Posts:
    34
    I've only done some quick testing, but removing any QoS Channels using StateUpdate/ReliableStateUpdate seems to improve things...
     
  10. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Not sure if this will help anyone out but I ran into a very similar error where a fragmented packet was getting garbled / garbling subsequent packets. In my case the problem was that the wrong buffer size was being passed to NetworkTransport.ReceiveFromHost.

    In 5.2 the buffer size needs to be 48*1024
    In 5.3 it should be NetworkMessage.MaxMessageSize
     
  11. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
  12. kicknshades

    kicknshades

    Joined:
    Jun 28, 2013
    Posts:
    1
    This issue still seems to be present in the latest beta, 5.4.0b20, where there is a very strange message ID and a stack trace indicating the game failed to allocate memory somewhere in it's networking code. Has anyone found a workaround or fix? Here is the information from the crash, which doesn't seem to be much different from the previous versions. This seems to be present on all versions, whether it's between an android client and standalone server, or standalone client and server.
     
  13. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    @kicknshades Yes it was a bug. It should be fixed in the last beta (fired today) and the next patch for 5.3 (will fired on June 15)