Skip to content

Commit a14a6fc

Browse files
committed
fix: avoiding throw from ResendMessages when send queue is full
1 parent 8bdb6c1 commit a14a6fc

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Assets/Mirage/Runtime/SocketLayer/Connection/AckSystem.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class AckSystem : IDisposable
3333

3434
// temp list for resending when processing sentqueue
3535
private readonly HashSet<ReliablePacket> _toResend = new HashSet<ReliablePacket>();
36+
private readonly List<ReliablePacket> _resendRemoveList = new List<ReliablePacket>();
3637
private readonly IRawConnection _connection;
3738
private readonly ITime _time;
3839
private readonly Pool<ByteBuffer> _bufferPool;
@@ -643,12 +644,35 @@ private void ReliableLost(ushort sequence, ReliablePacket reliablePacket)
643644

644645
private void ResendMessages()
645646
{
647+
if (_toResend.Count == 0)
648+
return;
649+
650+
_resendRemoveList.Clear();
651+
646652
foreach (var reliable in _toResend)
647653
{
654+
// exit early if we can't send any more packets
655+
if (_sentAckablePackets.Count >= _maxPacketsInSendBufferPerConnection)
656+
break;
657+
648658
_metrics?.OnResend(reliable.Length);
649659
SendReliablePacket(reliable);
660+
_resendRemoveList.Add(reliable);
661+
}
662+
663+
// if we sent all packets, we can just clear the set
664+
// otherwise we need to remove the ones we did send
665+
if (_resendRemoveList.Count == _toResend.Count)
666+
{
667+
_toResend.Clear();
668+
}
669+
else
670+
{
671+
foreach (var reliable in _resendRemoveList)
672+
{
673+
_toResend.Remove(reliable);
674+
}
650675
}
651-
_toResend.Clear();
652676
}
653677

654678
[MethodImpl(MethodImplOptions.AggressiveInlining)]

0 commit comments

Comments
 (0)