Pin the reset before a refusal's goodbye (cultmesh-ts, cultmesh-py) and C#'s once-guard

The document servers' refusal tests sent an unreliable fragment, whose
sequence the session never records, so dropping the reset before the goodbye
survived. They now refuse a reliable fragment and check the goodbye does not
acknowledge it.

C#: a BeforeSend seam orders a caller's failing send between the polling
thread's ack and its send, so both threads end the same session; the peer
hears one goodbye.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-30 16:02:27 +02:00
commit 2d76b8d1b6
4 changed files with 82 additions and 2 deletions

View file

@ -313,6 +313,42 @@ namespace GameCult.Networking.Tests
}
}
[Test]
public void ASessionEndedByACallerAndThePollingThreadTogetherSaysGoodbyeOnce()
{
var (server, listenerEndPoint, x, _) = TwoPeers(maxFragmentBytes: 1000);
using (server)
{
var ended = RecordDisconnects(server);
// The polling thread acknowledges X's frame outside the session's gate. Just before
// that ack goes out, a caller's send to X fails after its first fragment and ends the
// session; then the ack can never be sent either.
server.BeforeSend = (remote, packet) =>
{
if (!remote.Equals(x.EndPoint) || packet.PacketType != CultNetRudpPacketType.Ack)
return;
server.BeforeSend = null;
server.UnsendableAfter[x.EndPoint] = 1;
var caller = new Thread(() =>
{
try { server.SendSchema(x.Server, new byte[3000]); }
catch (SocketException) { }
});
caller.Start();
caller.Join();
server.UnsendableAfter[x.EndPoint] = 0;
};
x.Socket.SendTo(CultNetRudpPacketCodec.Encode(ReliableFrame(x, "from-x")), listenerEndPoint);
server.ReceiveOnce();
server.PollResends();
var goodbyes = Drain(x.Socket).Where(p => p.PacketType == CultNetRudpPacketType.Disconnect).ToList();
Assert.That(goodbyes, Has.Count.EqualTo(1));
Assert.That(ended, Is.EqualTo(new[] { x.Server }));
Assert.That(IsUnsendableReason(x.Server.DisconnectReason), Is.True);
}
}
[Test]
public void APermanentFailureInResendsEndsOnlyThatPeersSession()
{