MidLevel/Ruffles

ReliableChannel stops receiving after 65535 packets

neto-kokku opened this issue · 7 comments

else if (sequence == _incomingLowestAckedSequence + 1)

This line here is missing the cast to ushort, causing the ReliableChannel to stop accepting packets past sequence 65535.

Good catch, thanks!

The design is meant to roll over. I will work on fixing this.

Hey, has this been resolved yet or is there a work-around for it?

The Ruffles project looks awesome! :)

Just change the line to:
else if (sequence == (ushort)(_incomingLowestAckedSequence + 1))

Ohhhh... I wasn't even aware that this could grow out of the ushort size like this. The more you know! Thanks a lot <3 😄

C# doesn't have short/ushort literals, so the 1 in the expression is an int. Adding an ushort to an int returns an int, and comparing an ushort to an int implicitly casts the ushort to int. So when _incomingLowestAckedSequence is 65535 (the largest value an ushort can hold) the addition results in 65536 instead of wrapping around back to 0.

This was a really annoying bug do fix since it manifested as the game simply breaking down after playing for over 20 minutes or so.

This does make a lot of sense, you're right.

Glad you found it and shared it here to save everyone some time!

Here's a example where you can see this in action:
https://dotnetfiddle.net/dKKfaf