GameCult.Networking: resend the capped frame's answer until acknowledged, then end the session
Some checks failed
CultMesh QUIC native / Build win32-x64 (pull_request) Has been skipped
CultMesh QUIC native / Build linux-x64 (pull_request) Has been skipped
CultMesh QUIC native / Release native binaries (pull_request) Has been skipped
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Failing after 8m47s
CultMesh QUIC native / Verify committed binaries match SHA256SUMS (pull_request) Successful in 1m13s

The schema server answered the 8th undecodable frame and ended the peer's session in the same
call; ending clears the session's pending reliable packets, so a lost datagram was never
resent. The session now stays until the peer has acknowledged every answer (a lost one is
resent by PollResends) or a 2 s grace runs out, serves nothing after the capped frame
meanwhile, and then sends the goodbye.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Libby 2026-11-08 11:10:48 +00:00
commit 0b1a468ddd
3 changed files with 149 additions and 2 deletions

View file

@ -2759,6 +2759,11 @@ namespace GameCult.Networking
// under SessionGate by whichever thread's send found the failure; the polling thread reads
// it when it retires the peer.
internal byte[]? UnsendableReason { get; set; }
// Set once the peer's capped frame has been answered: the session ends with this reason when the
// peer has acknowledged every answer, or at the deadline. Under SessionGate.
internal byte[]? EndingReason { get; set; }
internal long EndingDeadlineMs { get; set; }
}
/// <summary>
@ -2928,6 +2933,7 @@ namespace GameCult.Networking
public bool TryReceiveOnce(out CultNetRudpSocketServerFrame? delivered)
{
RetireUnsendablePeers();
EndAnsweredPeers();
if (_deliveredFrames.Count > 0)
{
delivered = _deliveredFrames.Dequeue();
@ -3146,6 +3152,7 @@ namespace GameCult.Networking
public void PollResends()
{
RetireUnsendablePeers();
EndAnsweredPeers();
if (_socket.Poll(0, SelectMode.SelectRead))
return;
foreach (var peer in _peers.Values.ToArray())
@ -3244,6 +3251,44 @@ namespace GameCult.Networking
return true;
}
// Polling thread only. The application answered a peer's capped frame: the answer is reliable, so a
// lost datagram is resent, and the session ends with `reason` once the peer has acknowledged every
// answer or `graceMs` have passed (EndAnsweredPeers). Frames of the peer still queued are not delivered.
internal void EndPeerSessionWhenAnswered(CultNetRudpSocketServerPeer peer, byte[] reason, long graceMs)
{
if (peer == null) throw new ArgumentNullException(nameof(peer));
if (reason == null) throw new ArgumentNullException(nameof(reason));
lock (peer.SessionGate)
{
if (peer.Session.Ended || peer.EndingReason != null)
return;
peer.EndingReason = reason;
peer.EndingDeadlineMs = NowMs() + graceMs;
}
var kept = _deliveredFrames.Where(frame => !ReferenceEquals(frame.Peer, peer)).ToArray();
_deliveredFrames.Clear();
foreach (var frame in kept)
_deliveredFrames.Enqueue(frame);
}
// Polling thread only.
private void EndAnsweredPeers()
{
foreach (var peer in _peers.Values.ToArray())
{
byte[]? reason;
lock (peer.SessionGate)
{
reason = peer.EndingReason != null
&& (peer.Session.OutstandingReliablePacketCount == 0 || NowMs() >= peer.EndingDeadlineMs)
? peer.EndingReason
: null;
}
if (reason != null)
EndPeerSession(peer, reason);
}
}
// Polling thread only. A peer a new Connect already replaced was reported then, and its key now
// names the peer that replaced it.
private void RetireUnsendablePeers()