fix: Fix IORing disconnect issues. (#2335)

### Summary

- Bump IORingGroup 1.0.0 → 1.0.1 — fixes a disconnect handling bug in the native ring layer
- Fix ghost NetStates — Dispose() set _running = false before checking it, so the "force immediate disconnect" path
was dead code. Capture wasRunning before clearing it, add [Obsolete] guard, and route internal callers through
DisposeInternal()
- Fix unauthenticated socket cleanup — graceful disconnect on unauthed connections could get stuck with pending sends;
 now force-immediate after Disconnect() if DisconnectPending is already set
- Replace ConcurrentQueue<NetState> _disposed with Queue<NetState> — server is single-threaded; moved the field into
the Network partial class where it's consumed
- Move ConnectingSocketIdleLimit into the Network partial class alongside DisconnectUnattachedSockets
- Reset activity timer on receive, not just send — receiving data directly proves liveness instead of relying on the
ping→pong→send round-trip to reset the timer
- Move CheckAllAlive from Timer into Slice — the timer fired before I/O completions were processed, so after server
stalls (world saves), buffered client pings hadn't reset timestamps yet, causing false disconnects. Now runs at the
end of Slice() after all recv completions are handled
- Lower inactivity timeout 90s → 30s, check interval 90s → 5s — clients ping every ~1s, so 30s of silence is ~30
missed pings; worst-case detection drops from ~180s to ~35s
- Simplify CheckAlive — early-return when socket is null or alive; force-kill stuck DisconnectPending sockets
immediately instead of calling Disconnect() again
- Remove unused imports from GameEncryption.cs
This commit is contained in:
Kamron Batman 2026-02-13 23:05:20 -08:00 committed by GitHub
parent 4b392079e9
commit 6ffb63ec82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 16 deletions

View file

@ -21,7 +21,6 @@ using Server.Logging;
using Server.Menus;
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Net;
@ -34,14 +33,12 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
{
private static readonly ILogger logger = LogFactory.GetLogger(typeof(NetState));
private static readonly TimeSpan ConnectingSocketIdleLimit = TimeSpan.FromMilliseconds(5000); // 5 seconds
private const int HuePickerCap = 512;
private const int MenuCap = 512;
private const int PacketPerSecondThreshold = 3000;
private static readonly Queue<NetState> _flushPending = new(2048);
private static readonly Queue<NetState> _pendingDisconnects = new(256); // Processed AFTER flush
private static readonly ConcurrentQueue<NetState> _disposed = new();
private static readonly Queue<NetState> _throttled = new(256);
private static readonly Queue<NetState> _throttledPending = new(256);
@ -104,11 +101,6 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
ConfigureNetwork();
}
public static void Initialize()
{
Timer.DelayCall(TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1.5), CheckAllAlive);
}
// Internal constructor for accepted sockets
private NetState(RingSocket socket, IPAddress address)
{
@ -938,7 +930,17 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
public void CheckAlive(long curTicks)
{
if (_socket != null && NextActivityCheck - curTicks < 0)
if (_socket == null || NextActivityCheck - curTicks >= 0)
{
return;
}
if (_socket.DisconnectPending)
{
LogInfo("Force disconnecting stuck socket...");
_socketManager.DisconnectImmediate(_socket);
}
else
{
LogInfo("Disconnecting due to inactivity...");
Disconnect("Disconnecting due to inactivity.");
@ -1031,10 +1033,14 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
}
}
private void DisposeInternal() => Dispose();
// Do not run this directly. Use Disconnect instead.
// This is available for testing cleanup only.
[Obsolete("Use Disconnect instead")]
public void Dispose()
{
var wasRunning = _running;
_running = false;
// It's possible we could queue for dispose multiple times
if (_socket == null)
@ -1045,9 +1051,8 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
TraceDisconnect(_disconnectReason, _toString);
// If still running, force immediate disconnect
if (_running)
if (wasRunning)
{
_running = false;
_socketManager?.DisconnectImmediate(_socket);
}