Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Reliable messages don't arrive at the server

Discussion in 'Unity Transport' started by Life_Is_Good_, Aug 24, 2023.

  1. Life_Is_Good_

    Life_Is_Good_

    Joined:
    Mar 4, 2013
    Posts:
    41
    I'm using Unity Transport 1.4.
    I have an unreliable pipeline (NetworkPipeline.Null) and a reliable pipeline (ReliableSequencedPipelineStage) set up both on Server and Client.
    The unreliable pipeline works both ways, but it seems the reliable pipeline works only one way (Server to Client).
    I can send reliable messages over that pipeline and the Client receives those. The other way around I get a StatusCode.Success at the Client sending a message over the reliable pipeline but it never arrives at the Server.
    I couldn't really find anything relevant in the changelogs except for this in 2.0.0 exp 7:

    "Fixed issues with ReliableSequencePipelineStage that would, in rare circumstances, lead to failure to deliver a reliable packet."


    But it happens everytime all the time that the server doesn't receive the reliable message.
    Is this the same issue in 1.4.0?

    Edit: Updated to Unity Transport 2.0.2 and the issue is still there. It seems like it's pretty much impossible to debug on this end because there's essentially nothing exposed that could be debugged. The message just never arrives.
     
    Last edited: Aug 24, 2023
  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    416
    Any chance you can share the code sending/receiving these messages?
     
  3. Life_Is_Good_

    Life_Is_Good_

    Joined:
    Mar 4, 2013
    Posts:
    41
    Hi Simon, thanks for your answer. Was quite painful to track it down but I managed to find the issue.
    When a message is sent with a byte array of length 0 then apparently the whole message is discarded without any error/warning:

    Code (CSharp):
    1. var data = new byte[0];
    2. var dataNative = new NativeArray<byte>(data, Allocator.Temp);
    3.  
    4. DataStreamWriter writer;
    5. var result = driver.BeginSend(reliablePipeline, connection, out writer);
    6. writer.WriteBytes(dataNative);
    7. driver.EndSend(writer);
    In my case I didn't know that data was byte[0], the serializer that I use (Protobuf) apparently just discards bytes that are default values.
    What I find weird about that is that the message is just discarded though. I would expect for it to be send normally and then return NetworkEvent.Type = Empty when popped or again throw a warning/error.
     
  4. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    416
    Oh that's interesting. I was under the impression that we would send empty packets and report them back with a data event (and empty stream reader) to the receiver. Do you know if the packets you were sending on the unreliable pipeline were also empty? If so that would indicate a bug in the reliable pipeline, and is definitely something we'd want to fix.

    Thanks for reporting back! Appreciate you taking the time to detail your findings.
     
  5. Life_Is_Good_

    Life_Is_Good_

    Joined:
    Mar 4, 2013
    Posts:
    41
    I just tested it. Empty messages over the reliable pipeline are sent, but are tagged with NetworkEvent.Type = Data instead of Empty and a null stream reader.
     
  6. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    416
    Alright, thanks for testing it. Looks like we have a discrepancy in how we handle empty messages on different pipelines. I've filed a bug on our end to address this. Thanks for the report!
     
    Life_Is_Good_ likes this.
  7. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    416
    Small update on this: we've identified a fix for the issue. It should be part of the next Unity Transport release (probably 2.1.0). With the fix applied, you'll get a data event even for empty messages, no matter on which pipeline it is sent.