mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-06 23:34:13 +02:00
Temp diagnostics
This commit is contained in:
@@ -38,7 +38,9 @@ public sealed class IrcGatewayService : BackgroundService
|
|||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
|
Console.Error.WriteLine("[DIAG] IrcGatewayService.ExecuteAsync entered.");
|
||||||
await Task.Yield();
|
await Task.Yield();
|
||||||
|
Console.Error.WriteLine($"[DIAG] IrcGatewayService.ExecuteAsync resumed after Task.Yield(). Enabled={_options.Enabled}");
|
||||||
|
|
||||||
if (!_options.Enabled)
|
if (!_options.Enabled)
|
||||||
{
|
{
|
||||||
@@ -141,8 +143,10 @@ public sealed class IrcGatewayService : BackgroundService
|
|||||||
|
|
||||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
Console.Error.WriteLine("[DIAG] IrcGatewayService.StopAsync entered.");
|
||||||
// Cancel ExecuteAsync first so listeners stop accepting
|
// Cancel ExecuteAsync first so listeners stop accepting
|
||||||
await base.StopAsync(cancellationToken);
|
await base.StopAsync(cancellationToken);
|
||||||
|
Console.Error.WriteLine("[DIAG] IrcGatewayService.StopAsync: base.StopAsync returned.");
|
||||||
|
|
||||||
// Force-close any remaining client connections
|
// Force-close any remaining client connections
|
||||||
foreach (var (_, conn) in _connections)
|
foreach (var (_, conn) in _connections)
|
||||||
|
|||||||
@@ -169,7 +169,9 @@ while (true)
|
|||||||
await using var app = builder.Build();
|
await using var app = builder.Build();
|
||||||
|
|
||||||
// ── Database initialization ──────────────────────────────────────────
|
// ── Database initialization ──────────────────────────────────────────
|
||||||
|
Console.Error.WriteLine("[DIAG] Database initialization starting...");
|
||||||
await DatabaseSetup.InitializeAsync(app.Services);
|
await DatabaseSetup.InitializeAsync(app.Services);
|
||||||
|
Console.Error.WriteLine("[DIAG] Database initialization complete.");
|
||||||
|
|
||||||
// ── Middleware ────────────────────────────────────────────────────────
|
// ── Middleware ────────────────────────────────────────────────────────
|
||||||
app.UseCors();
|
app.UseCors();
|
||||||
@@ -181,7 +183,9 @@ while (true)
|
|||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.MapHub<ChatHub>(HubConstants.ChatHubPath);
|
app.MapHub<ChatHub>(HubConstants.ChatHubPath);
|
||||||
|
|
||||||
|
Console.Error.WriteLine("[DIAG] Calling app.RunAsync()...");
|
||||||
await app.RunAsync();
|
await app.RunAsync();
|
||||||
|
Console.Error.WriteLine("[DIAG] app.RunAsync() returned.");
|
||||||
|
|
||||||
// Graceful shutdown (Ctrl+C) — exit the loop
|
// Graceful shutdown (Ctrl+C) — exit the loop
|
||||||
Log.Information("Server shut down gracefully");
|
Log.Information("Server shut down gracefully");
|
||||||
@@ -189,6 +193,8 @@ while (true)
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Console.Error.WriteLine($"[DIAG] Top-level exception: {ex}");
|
||||||
|
|
||||||
var uptime = DateTimeOffset.UtcNow - startTime;
|
var uptime = DateTimeOffset.UtcNow - startTime;
|
||||||
|
|
||||||
// If server ran for over 60 seconds, it's a runtime crash — reset failure count
|
// If server ran for over 60 seconds, it's a runtime crash — reset failure count
|
||||||
@@ -211,4 +217,6 @@ while (true)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console.Error.WriteLine("[DIAG] Calling Log.CloseAndFlush()...");
|
||||||
Log.CloseAndFlush();
|
Log.CloseAndFlush();
|
||||||
|
Console.Error.WriteLine("[DIAG] Log.CloseAndFlush() done. Exiting process.");
|
||||||
|
|||||||
@@ -17,10 +17,13 @@ public sealed class ServerDirectoryService(
|
|||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
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
|
// Yield to let the host finish starting before we log or connect
|
||||||
await Task.Yield();
|
await Task.Yield();
|
||||||
|
Console.Error.WriteLine("[DIAG] ServerDirectoryService.ExecuteAsync resumed after Task.Yield().");
|
||||||
|
|
||||||
var isPublic = configuration.GetValue<bool>("Server:PublicServer");
|
var isPublic = configuration.GetValue<bool>("Server:PublicServer");
|
||||||
|
Console.Error.WriteLine($"[DIAG] ServerDirectoryService: PublicServer={isPublic}");
|
||||||
if (!isPublic)
|
if (!isPublic)
|
||||||
{
|
{
|
||||||
logger.LogInformation("PublicServer is disabled — not registering with directory");
|
logger.LogInformation("PublicServer is disabled — not registering with directory");
|
||||||
@@ -28,6 +31,7 @@ public sealed class ServerDirectoryService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var host = configuration["Server:PublicHost"];
|
var host = configuration["Server:PublicHost"];
|
||||||
|
Console.Error.WriteLine($"[DIAG] ServerDirectoryService: PublicHost={host}");
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(host))
|
if (string.IsNullOrWhiteSpace(host))
|
||||||
{
|
{
|
||||||
@@ -48,6 +52,7 @@ public sealed class ServerDirectoryService(
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Console.Error.WriteLine("[DIAG] ServerDirectoryService: Building new connection, entering try block.");
|
||||||
var connectionPermanentlyClosed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
var connectionPermanentlyClosed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
|
||||||
connection.Reconnected += async _ =>
|
connection.Reconnected += async _ =>
|
||||||
@@ -69,9 +74,14 @@ public sealed class ServerDirectoryService(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Connect with retry
|
// Connect with retry
|
||||||
|
Console.Error.WriteLine("[DIAG] ServerDirectoryService: Calling ConnectWithRetryAsync...");
|
||||||
if (!await ConnectWithRetryAsync(connection, stoppingToken))
|
if (!await ConnectWithRetryAsync(connection, stoppingToken))
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine("[DIAG] ServerDirectoryService: ConnectWithRetryAsync returned false (cancelled).");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.Error.WriteLine("[DIAG] ServerDirectoryService: Connected successfully!");
|
||||||
logger.LogInformation("Successfully connected to EchoHubSpace API at {Url}", DirectoryHubUrl);
|
logger.LogInformation("Successfully connected to EchoHubSpace API at {Url}", DirectoryHubUrl);
|
||||||
await RegisterAsync(serverName, description, host);
|
await RegisterAsync(serverName, description, host);
|
||||||
|
|
||||||
@@ -188,20 +198,25 @@ public sealed class ServerDirectoryService(
|
|||||||
|
|
||||||
private static async Task DisposeConnectionAsync(HubConnection connection)
|
private static async Task DisposeConnectionAsync(HubConnection connection)
|
||||||
{
|
{
|
||||||
|
Console.Error.WriteLine("[DIAG] ServerDirectoryService.DisposeConnectionAsync entered.");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await connection.DisposeAsync()
|
await connection.DisposeAsync()
|
||||||
.AsTask().WaitAsync(TimeSpan.FromSeconds(3));
|
.AsTask().WaitAsync(TimeSpan.FromSeconds(3));
|
||||||
|
Console.Error.WriteLine("[DIAG] ServerDirectoryService.DisposeConnectionAsync completed normally.");
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
Console.Error.WriteLine("[DIAG] ServerDirectoryService.DisposeConnectionAsync timed out or failed (3s).");
|
||||||
// Don't let a slow dispose block shutdown
|
// Don't let a slow dispose block shutdown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
Console.Error.WriteLine("[DIAG] ServerDirectoryService.StopAsync entered.");
|
||||||
await base.StopAsync(cancellationToken);
|
await base.StopAsync(cancellationToken);
|
||||||
|
Console.Error.WriteLine("[DIAG] ServerDirectoryService.StopAsync: base.StopAsync returned.");
|
||||||
_connection = null;
|
_connection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user