diff --git a/src/EchoHub.Server.Irc/IrcGatewayService.cs b/src/EchoHub.Server.Irc/IrcGatewayService.cs index 5515b9c..6f063a5 100644 --- a/src/EchoHub.Server.Irc/IrcGatewayService.cs +++ b/src/EchoHub.Server.Irc/IrcGatewayService.cs @@ -39,9 +39,7 @@ public sealed class IrcGatewayService : BackgroundService protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - Console.Error.WriteLine("[DIAG] IrcGatewayService.ExecuteAsync entered."); await Task.Yield(); - Console.Error.WriteLine($"[DIAG] IrcGatewayService.ExecuteAsync resumed after Task.Yield(). Enabled={_options.Enabled}"); if (!_options.Enabled) { @@ -149,10 +147,8 @@ public sealed class IrcGatewayService : BackgroundService public override async Task StopAsync(CancellationToken cancellationToken) { - Console.Error.WriteLine("[DIAG] IrcGatewayService.StopAsync entered."); // Cancel ExecuteAsync first so listeners stop accepting await base.StopAsync(cancellationToken); - Console.Error.WriteLine("[DIAG] IrcGatewayService.StopAsync: base.StopAsync returned."); // Force-close any remaining client connections foreach (var (_, conn) in _connections) diff --git a/src/EchoHub.Server/Program.cs b/src/EchoHub.Server/Program.cs index 809355e..f5a38a9 100644 --- a/src/EchoHub.Server/Program.cs +++ b/src/EchoHub.Server/Program.cs @@ -169,9 +169,7 @@ while (true) await using var app = builder.Build(); // ── Database initialization ────────────────────────────────────────── - Console.Error.WriteLine("[DIAG] Database initialization starting..."); await DatabaseSetup.InitializeAsync(app.Services); - Console.Error.WriteLine("[DIAG] Database initialization complete."); // ── Middleware ──────────────────────────────────────────────────────── app.UseCors(); @@ -183,65 +181,7 @@ while (true) app.MapControllers(); app.MapHub(HubConstants.ChatHubPath); - // ── Diagnostic hooks ──────────────────────────────────────────────── - app.Lifetime.ApplicationStarted.Register( - () => Console.Error.WriteLine("[DIAG] ApplicationStarted fired")); - app.Lifetime.ApplicationStopping.Register( - () => Console.Error.WriteLine("[DIAG] ApplicationStopping fired")); - app.Lifetime.ApplicationStopped.Register( - () => Console.Error.WriteLine("[DIAG] ApplicationStopped fired")); - - // Heartbeat — proves the process is alive even if nothing else logs - var heartbeatCts = new CancellationTokenSource(); - _ = Task.Run(async () => - { - while (!heartbeatCts.Token.IsCancellationRequested) - { - await Task.Delay(5000, heartbeatCts.Token).ConfigureAwait(false); - Console.Error.WriteLine($"[DIAG] heartbeat {DateTimeOffset.UtcNow:HH:mm:ss}"); - } - }, heartbeatCts.Token); - - // ── Config diagnostics ───────────────────────────────────────────── - Console.Error.WriteLine($"[DIAG] Irc:Enabled = {app.Configuration.GetValue("Irc:Enabled")}"); - Console.Error.WriteLine($"[DIAG] Environment = {app.Environment.EnvironmentName}"); - - // ── Resolve singletons one-by-one to find which one hangs ──────── - Console.Error.WriteLine("[DIAG] Resolving PresenceTracker..."); - _ = app.Services.GetRequiredService(); - Console.Error.WriteLine("[DIAG] PresenceTracker OK."); - - Console.Error.WriteLine("[DIAG] Resolving JwtTokenService..."); - _ = app.Services.GetRequiredService(); - Console.Error.WriteLine("[DIAG] JwtTokenService OK."); - - Console.Error.WriteLine("[DIAG] Resolving FileStorageService..."); - _ = app.Services.GetRequiredService(); - Console.Error.WriteLine("[DIAG] FileStorageService OK."); - - Console.Error.WriteLine("[DIAG] Resolving IChatBroadcaster..."); - _ = app.Services.GetServices().ToList(); - Console.Error.WriteLine("[DIAG] IChatBroadcaster OK."); - - Console.Error.WriteLine("[DIAG] Resolving IChatService..."); - _ = app.Services.GetRequiredService(); - Console.Error.WriteLine("[DIAG] IChatService OK."); - - Console.Error.WriteLine("[DIAG] Resolving IHostedService instances..."); - var hostedServices = app.Services.GetServices().ToList(); - Console.Error.WriteLine($"[DIAG] Found {hostedServices.Count} hosted services:"); - foreach (var svc in hostedServices) - Console.Error.WriteLine($"[DIAG] - {svc.GetType().FullName}"); - Console.Error.Flush(); - - // ── Start with per-service timing ───────────────────────────────── - Console.Error.WriteLine("[DIAG] Calling app.StartAsync()..."); - await app.StartAsync(); - Console.Error.WriteLine("[DIAG] app.StartAsync() completed — server is running."); - - await app.WaitForShutdownAsync(); - Console.Error.WriteLine("[DIAG] WaitForShutdownAsync returned."); - heartbeatCts.Cancel(); + await app.RunAsync(); // Graceful shutdown (Ctrl+C) — exit the loop Log.Information("Server shut down gracefully"); @@ -249,8 +189,6 @@ while (true) } catch (Exception ex) { - Console.Error.WriteLine($"[DIAG] Top-level exception: {ex}"); - var uptime = DateTimeOffset.UtcNow - startTime; // If server ran for over 60 seconds, it's a runtime crash — reset failure count @@ -273,6 +211,4 @@ while (true) } } -Console.Error.WriteLine("[DIAG] Calling Log.CloseAndFlush()..."); Log.CloseAndFlush(); -Console.Error.WriteLine("[DIAG] Log.CloseAndFlush() done. Exiting process."); diff --git a/src/EchoHub.Server/Services/ServerDirectoryService.cs b/src/EchoHub.Server/Services/ServerDirectoryService.cs index 69b44ee..75b3784 100644 --- a/src/EchoHub.Server/Services/ServerDirectoryService.cs +++ b/src/EchoHub.Server/Services/ServerDirectoryService.cs @@ -28,13 +28,10 @@ public sealed class ServerDirectoryService : BackgroundService protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - Console.Error.WriteLine("[DIAG] ServerDirectoryService.ExecuteAsync entered."); // Yield to let the host finish starting before we log or connect await Task.Yield(); - Console.Error.WriteLine("[DIAG] ServerDirectoryService.ExecuteAsync resumed after Task.Yield()."); var isPublic = _configuration.GetValue("Server:PublicServer"); - Console.Error.WriteLine($"[DIAG] ServerDirectoryService: PublicServer={isPublic}"); if (!isPublic) { _logger.LogInformation("PublicServer is disabled — not registering with directory"); @@ -42,7 +39,6 @@ public sealed class ServerDirectoryService : BackgroundService } var host = _configuration["Server:PublicHost"]; - Console.Error.WriteLine($"[DIAG] ServerDirectoryService: PublicHost={host}"); if (string.IsNullOrWhiteSpace(host)) { @@ -63,7 +59,6 @@ public sealed class ServerDirectoryService : BackgroundService try { - Console.Error.WriteLine("[DIAG] ServerDirectoryService: Building new connection, entering try block."); var connectionPermanentlyClosed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection.Reconnected += async _ => @@ -85,14 +80,9 @@ public sealed class ServerDirectoryService : BackgroundService }; // Connect with retry - Console.Error.WriteLine("[DIAG] ServerDirectoryService: Calling ConnectWithRetryAsync..."); if (!await ConnectWithRetryAsync(connection, stoppingToken)) - { - Console.Error.WriteLine("[DIAG] ServerDirectoryService: ConnectWithRetryAsync returned false (cancelled)."); return; - } - Console.Error.WriteLine("[DIAG] ServerDirectoryService: Connected successfully!"); _logger.LogInformation("Successfully connected to EchoHubSpace API at {Url}", DirectoryHubUrl); await RegisterAsync(serverName, description, host); @@ -209,25 +199,20 @@ public sealed class ServerDirectoryService : BackgroundService private static async Task DisposeConnectionAsync(HubConnection connection) { - Console.Error.WriteLine("[DIAG] ServerDirectoryService.DisposeConnectionAsync entered."); try { await connection.DisposeAsync() .AsTask().WaitAsync(TimeSpan.FromSeconds(3)); - Console.Error.WriteLine("[DIAG] ServerDirectoryService.DisposeConnectionAsync completed normally."); } catch { - Console.Error.WriteLine("[DIAG] ServerDirectoryService.DisposeConnectionAsync timed out or failed (3s)."); // Don't let a slow dispose block shutdown } } public override async Task StopAsync(CancellationToken cancellationToken) { - Console.Error.WriteLine("[DIAG] ServerDirectoryService.StopAsync entered."); await base.StopAsync(cancellationToken); - Console.Error.WriteLine("[DIAG] ServerDirectoryService.StopAsync: base.StopAsync returned."); _connection = null; }