Search Unity

[BUG] NetworkConnection.SetMaxDelay() does nothing, ChannelBuffer.m_LastFlushTime is always zero!

Discussion in 'Multiplayer' started by Slight0, Aug 23, 2015.

  1. Slight0

    Slight0

    Joined:
    Dec 6, 2013
    Posts:
    28
    Problem: NetworkConnection.SetMaxDelay(float) has no effect because ChannelBuffer.m_LastFlushTime is never set. This means that the buffer is flushed every update instead of every maxDelay seconds.

    Solution: Set m_LastFlushTime to Time.time inside the ChannelBuffer.SendInternalBuffer() method.

    Code showing the issue (decompiled from UnityEngine.Networking.dll)

    ChannelBuffer.cs
    Code (CSharp):
    1.  
    2. //This is the only place that m_LastFlushTime is referenced; it is never set besides in the constructor
    3. public void CheckInternalBuffer()
    4. {
    5.     if (((Time.time - this.m_LastFlushTime) > this.maxDelay) && !this.m_CurrentPacket.IsEmpty())
    6.     {
    7.         this.SendInternalBuffer();
    8.     }
    9.     if ((Time.time - this.m_LastBufferedMessageCountTimer) > 1f)
    10.     {
    11.         this.lastBufferedPerSecond = this.numBufferedPerSecond;
    12.         this.numBufferedPerSecond = 0;
    13.         this.m_LastBufferedMessageCountTimer = Time.time;
    14.     }
    15. }
    16.  
    17. //This function should be setting m_LastFlushTime but it does not.
    18. public bool SendInternalBuffer()
    19. {
    20.     NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, 0x1d, "msg", 1);
    21.     if (!this.m_isReliable || (this.m_PendingPackets.Count <= 0))
    22.     {
    23.         return this.m_CurrentPacket.SendToTransport(this.m_hostId, this.m_connectionId, this.m_channelId);
    24.     }
    25.     while (this.m_PendingPackets.Count > 0)
    26.     {
    27.         ChannelPacket packet = this.m_PendingPackets[0];
    28.         if (!packet.SendToTransport(this.m_hostId, this.m_connectionId, this.m_channelId))
    29.         {
    30.             break;
    31.         }
    32.         s_PendingPacketCount--;
    33.         this.m_PendingPackets.RemoveAt(0);
    34.         FreePacket(packet);
    35.         if (this.m_isBroken && (this.m_PendingPackets.Count < (this.m_maxPendingPacketCount / 2)))
    36.         {
    37.             if (LogFilter.logWarn)
    38.             {
    39.                 Debug.LogWarning("ChannelBuffer recovered from overflow but data was lost.");
    40.             }
    41.             this.m_isBroken = false;
    42.         }
    43.     }
    44.     return true;
    45. }
    46.  
    NetworkConnection.cs
    Code (CSharp):
    1. internal void FlushInternalBuffer()
    2.         {
    3.             if (this.m_Channels != null)
    4.             {
    5.                 foreach (ChannelBuffer buffer in this.m_Channels)
    6.                 {
    7.                     buffer.CheckInternalBuffer();
    8.                 }
    9.             }
    10.         }
    NetworkConnection.FlushInternalBuffer() is called every update on both client and server for each connection present.

    I have verified this bug with the debugger. For all connections, on client or server, the m_LastFlushTime field is always 0f.
     
    Last edited: Aug 23, 2015
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    FYI that bug is fixed in 5.2
     
  3. Slight0

    Slight0

    Joined:
    Dec 6, 2013
    Posts:
    28
    Good to know, thanks.