GameCult.Networking: a Connect that replaces a peer ends the old peer's session under its gate
A caller still holding the replaced peer (a schema handler awaiting work for it) could send into the endpoint the new session owns: a goodbye after a partial failure disconnected the new client, a fixed initial sequence delivered the stale frame in place of the real one, and a drawn one stalled the new session. The replaced session now ends under the SessionGate every Send takes, so a stale Send throws and nothing of it leaves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1f25195afe
commit
e8e8e5bac1
2 changed files with 70 additions and 18 deletions
|
|
@ -2966,14 +2966,20 @@ namespace GameCult.Networking
|
|||
_peers.TryGetValue(peerKey, out var admitted);
|
||||
// The admitted peer's session decides whether this Connect repeats the one it accepted:
|
||||
// answer a repeat with the Accept already owed and queue nothing. Any other Connect is
|
||||
// a new generation.
|
||||
// a new generation, and the admitted peer's session ends here, under the gate every
|
||||
// Send takes: a caller still holding the replaced peer can send nothing more into the
|
||||
// endpoint the new session now owns.
|
||||
if (admitted != null)
|
||||
{
|
||||
var repeats = false;
|
||||
SocketException? unsendableReply = null;
|
||||
lock (admitted.SessionGate)
|
||||
{
|
||||
if (admitted.Session.ConnectRepeats(packet))
|
||||
if (!admitted.Session.ConnectRepeats(packet))
|
||||
{
|
||||
admitted.Session.ResetPeerState();
|
||||
}
|
||||
else
|
||||
{
|
||||
repeats = true;
|
||||
CultNetRudpPacket reply;
|
||||
|
|
@ -3012,11 +3018,15 @@ namespace GameCult.Networking
|
|||
unsendableAccept = SendPacket(peer.RemoteEndPoint, peer.Session.AcceptConnect(packet, NowMs(), _acceptPayload));
|
||||
if (unsendableAccept != null)
|
||||
{
|
||||
// The peer cannot be answered, so no session starts.
|
||||
// The peer cannot be answered, so no session starts, and the one it replaced has
|
||||
// already ended.
|
||||
_peers.Remove(peerKey);
|
||||
_stats.PacketsDropped++;
|
||||
return true;
|
||||
}
|
||||
_peers[peerKey] = peer;
|
||||
else
|
||||
{
|
||||
_peers[peerKey] = peer;
|
||||
}
|
||||
if (admitted != null)
|
||||
{
|
||||
admitted.DisconnectReason = ReplacedPeerReason;
|
||||
|
|
|
|||
Loading…
Reference in a new issue