RUDP: evict the least recently touched fragment set in every runtime; document the bare receive refusal

The pending-fragment bound evicted the first non-reliable set in insertion
order in TypeScript and Python, so a set actively receiving could be the
victim. Rust already took the least recently touched set. TS and Python now
track a per-set touch counter and match Rust. A test in each runtime pins the
scenario: bound full, the oldest set receives another fragment, a new set
forces one eviction, and the oldest set still completes.

Session receive in all three runtimes now documents that a refusal error ends
the session and the caller must end it, since the refused sequence is already
recorded and would be acknowledged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-30 00:27:41 +02:00
commit 848b423d9c
6 changed files with 122 additions and 18 deletions

View file

@ -2308,6 +2308,22 @@ class CultNetRudpFragmentBoundTests(unittest.TestCase):
self.assertEqual(receiver.receive(stranded[0]).delivered, ())
def test_eviction_takes_the_least_recently_touched_set_not_the_actively_receiving_one(self) -> None:
sender, receiver = self._pair()
receiver._max_pending_fragment_sets = 4
sets = []
for fill in range(1, 5):
packets = sender.send_many("media", bytes([fill]) * 2500, max_fragment_bytes=1000)
self.assertEqual(receiver.receive(packets[0]).delivered, ())
sets.append(packets)
# Set 1 is the oldest but is still receiving.
self.assertEqual(receiver.receive(sets[0][1]).delivered, ())
# A fifth set forces an eviction: the stalled set 2, not set 1.
fifth = sender.send_many("media", bytes([5]) * 2500, max_fragment_bytes=1000)
self.assertEqual(receiver.receive(fifth[0]).delivered, ())
self.assertEqual(receiver.fragment_sets_evicted, 1)
self.assertEqual(receiver.receive(sets[0][2]).delivered[0].payload, bytes([1]) * 2500)
def test_a_reliable_fragment_set_is_never_evicted_and_a_full_reliable_bound_refuses(self) -> None:
sender, receiver = self._pair()
receiver._max_pending_fragment_sets = 4