feat: port session 10 — Server Core Runtime, Accept Loops & Listeners

Ports server/server.go lines 2577–4782 (~1,881 Go LOC), implementing ~97
features (IDs 3051–3147) across three new partial-class files.

New files:
- NatsServer.Lifecycle.cs: Shutdown, WaitForShutdown, RemoveClient,
  SendLDMToClients, LameDuckMode, LDMClientByID, rate-limit logging,
  DisconnectClientByID, SendAsyncInfoToClients
- NatsServer.Listeners.cs: AcceptLoop, GetServerListener, InProcessConn,
  AcceptConnections, GenerateInfoJson, CopyInfo, CreateClient/Ex/InProcess,
  StartMonitoring (HTTP/HTTPS), AddConnectURLs/RemoveConnectURLs,
  TlsVersion/TlsVersionFromString, GetClientConnectURLs, ResolveHostPorts,
  PortsInfo/PortFile/LogPorts, ReadyForListeners, GetRandomIP, AcceptError
- Internal/WaitGroup.cs: Go-style WaitGroup using TaskCompletionSource

Modified:
- Auth/AuthTypes.cs: Account now implements INatsAccount (stub)
- NatsServerTypes.cs: ServerInfo.ShallowClone(), removed duplicate RefCountedUrlSet
- NatsServer.cs: _info promoted to internal for test access
- Properties/AssemblyInfo.cs: InternalsVisibleTo(DynamicProxyGenAssembly2)
- ServerTests.cs: 20 new session-10 unit tests (GenerateInfoJson, TlsVersion,
  CopyInfo, GetRandomIP — Test IDs 2895, 2906)

All 565 unit tests + 1 integration test pass.
This commit is contained in:
Joseph Doherty
2026-02-26 15:08:23 -05:00
parent 0df93c23b0
commit 06779a1f77
13 changed files with 2539 additions and 21 deletions

View File

@@ -76,7 +76,7 @@ public sealed partial class NatsServer : INatsServer
private readonly ReaderWriterLockSlim _mu = new(LockRecursionPolicy.SupportsRecursion);
private readonly ReaderWriterLockSlim _reloadMu = new(LockRecursionPolicy.SupportsRecursion);
private ServerInfo _info = new();
internal ServerInfo _info = new();
private string _configFile = string.Empty;
// =========================================================================
@@ -104,6 +104,34 @@ public sealed partial class NatsServer : INatsServer
private System.Net.Sockets.TcpListener? _listener;
private Exception? _listenerErr;
// HTTP monitoring listener
private System.Net.Sockets.TcpListener? _http;
// Route listener
private System.Net.Sockets.TcpListener? _routeListener;
private Exception? _routeListenerErr;
// Gateway listener
private System.Net.Sockets.TcpListener? _gatewayListener;
private Exception? _gatewayListenerErr;
// Leaf-node listener
private System.Net.Sockets.TcpListener? _leafNodeListener;
private Exception? _leafNodeListenerErr;
// Profiling listener
private System.Net.Sockets.TcpListener? _profiler;
// Accept-loop done channel — each accept loop sends true when it exits.
private readonly System.Threading.Channels.Channel<bool> _done =
System.Threading.Channels.Channel.CreateUnbounded<bool>();
// Lame-duck channel — created in lameDuckMode, receives one signal per accept loop.
private System.Threading.Channels.Channel<bool>? _ldmCh;
// The no-auth user that only the system account can use (auth session).
private string _sysAccOnlyNoAuthUser = string.Empty;
// =========================================================================
// Accounts
// =========================================================================
@@ -153,7 +181,7 @@ public sealed partial class NatsServer : INatsServer
private readonly object _grMu = new();
private bool _grRunning;
private readonly Dictionary<ulong, ClientConnection> _grTmpClients = [];
private readonly SemaphoreSlim _grWg = new(1, 1); // simplified wg
private readonly WaitGroup _grWg = new();
// =========================================================================
// Cluster name (separate lock)