diff --git a/src/Managing.Bootstrap/ApiBootstrap.cs b/src/Managing.Bootstrap/ApiBootstrap.cs index 5cdfcc8f..10ce2f87 100644 --- a/src/Managing.Bootstrap/ApiBootstrap.cs +++ b/src/Managing.Bootstrap/ApiBootstrap.cs @@ -1,4 +1,5 @@ using System.Net; +using System.Net.Sockets; using System.Reflection; using Discord.Commands; using Discord.WebSocket; @@ -113,10 +114,33 @@ public static class ApiBootstrap Environment.GetEnvironmentVariable("COMPUTERNAME") ?? // Windows hostname "localhost"; + // Parse the hostname to IP address for Orleans + IPAddress advertisedIP; + if (IPAddress.TryParse(hostname, out advertisedIP)) + { + // hostname is already an IP address + } + else + { + // Try to resolve hostname to IP address + try + { + var hostEntry = Dns.GetHostEntry(hostname); + advertisedIP = hostEntry.AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork) + ?? hostEntry.AddressList.FirstOrDefault(); + } + catch + { + // Fallback to localhost if resolution fails + advertisedIP = IPAddress.Loopback; + } + } + var postgreSqlConnectionString = configuration.GetSection("PostgreSql")["Orleans"]; Console.WriteLine($"Task Slot: {taskSlot}"); Console.WriteLine($"Hostname: {hostname}"); + Console.WriteLine($"Advertised IP: {advertisedIP}"); Console.WriteLine($"Silo port: {siloPort}"); Console.WriteLine($"Gateway port: {gatewayPort}"); Console.WriteLine($"Dashboard port: {dashboardPort}"); @@ -132,7 +156,7 @@ public static class ApiBootstrap options.ConnectionString = postgreSqlConnectionString; options.Invariant = "Npgsql"; }) - .ConfigureEndpoints(IPAddress.Any, siloPort, gatewayPort) + .ConfigureEndpoints(advertisedIP, siloPort, gatewayPort) .Configure(options => { options.ServiceId = "ManagingApp"; @@ -161,7 +185,7 @@ public static class ApiBootstrap }); } - // Configure networking - use Any for Docker containerized environments + // Configure networking - use specific IP for Docker containerized environments if (disableOrleansClustering) { // Use localhost clustering when clustering is disabled @@ -169,8 +193,8 @@ public static class ApiBootstrap } else if (string.IsNullOrEmpty(postgreSqlConnectionString)) { - // In Docker/containerized environments, use Any to allow inter-container communication - siloBuilder.ConfigureEndpoints(IPAddress.Any, siloPort, gatewayPort); + // In Docker/containerized environments, use the resolved IP address + siloBuilder.ConfigureEndpoints(advertisedIP, siloPort, gatewayPort); } siloBuilder