# Session 10: Server Core — Runtime & Lifecycle ## Summary Second half of server.go: accept loops, client creation, monitoring HTTP server, TLS handling, lame duck mode, shutdown, and runtime query methods. ## Scope | Go File | Features | Feature IDs | Go LOC | |---------|----------|-------------|--------| | server/server.go (lines 2577–4782) | ~98 | 3051–3147 | ~1,881 | | **Total** | **~98** | | **~1,881** | ### Key Features - `Shutdown` — graceful shutdown (172 LOC) - `AcceptLoop`, `acceptConnections` — TCP listener - `createClientEx` — client connection factory (305 LOC) - `startMonitoring`, `StartHTTPMonitoring` — HTTP monitoring server - `lameDuckMode`, `sendLDMToRoutes`, `sendLDMToClients` — lame duck - `readyForConnections`, `readyForListeners` — startup synchronization - Numerous `Num*` query methods (routes, clients, subscriptions, etc.) - `getConnectURLs`, `PortsInfo` — connection metadata - `removeClient`, `saveClosedClient` — client lifecycle ## .NET Classes - `NatsServer` (partial — runtime, lifecycle, queries) - `CaptureHTTPServerLog` — HTTP log adapter - `TlsMixConn` — mixed TLS/plain connection ## Test Files | Test File | Tests | Test IDs | |-----------|-------|----------| | server/server_test.go (partial) | ~22 | 2886–2907 | | server/benchmark_publish_test.go | 1 | 154 | | server/core_benchmarks_test.go | 4 | 274–277 | | **Total** | **~27** | | ## Dependencies - Session 09 (Server Core Part 1) - Session 08 (Client Connection) - Session 04 (Logging) ## .NET Target Location - `dotnet/src/ZB.MOM.NatsNet.Server/NatsServer.cs` (partial class) - Consider: `NatsServer.Lifecycle.cs`, `NatsServer.Listeners.cs` ## Notes - `createClientEx` is 305 LOC — second largest function in the file - `Shutdown` involves coordinating across all subsystems - Monitoring HTTP server maps to ASP.NET Core Kestrel or minimal API - Lame duck mode requires careful timer/signal coordination