From 7271889bdfa7860872fc9edf30ab7d48f87ca50b Mon Sep 17 00:00:00 2001 From: cryptooda Date: Sat, 16 Aug 2025 06:21:26 +0700 Subject: [PATCH] Fix orleans local --- src/Managing.Bootstrap/ApiBootstrap.cs | 31 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Managing.Bootstrap/ApiBootstrap.cs b/src/Managing.Bootstrap/ApiBootstrap.cs index c589bb4..45b0362 100644 --- a/src/Managing.Bootstrap/ApiBootstrap.cs +++ b/src/Managing.Bootstrap/ApiBootstrap.cs @@ -97,9 +97,10 @@ public static class ApiBootstrap return hostBuilder.UseOrleans(siloBuilder => { - // Configure clustering with improved networking or use localhost clustering if disabled - if (!disableOrleansClustering && !string.IsNullOrEmpty(postgreSqlConnectionString)) + // Configure clustering - force localhost clustering in development mode + if (!disableOrleansClustering && !string.IsNullOrEmpty(postgreSqlConnectionString) && isProduction) { + // Only use ADO.NET clustering in production siloBuilder .UseAdoNetClustering(options => { @@ -109,12 +110,12 @@ public static class ApiBootstrap } else { - // Fallback to localhost clustering for testing or when database is unavailable + // Use localhost clustering for development or when database is unavailable siloBuilder.UseLocalhostClustering(); } - // Conditionally configure reminder service based on flag - if (runOrleansGrains && !disableOrleansClustering && !string.IsNullOrEmpty(postgreSqlConnectionString)) + // Conditionally configure reminder service based on flag - only in production with ADO.NET clustering + if (runOrleansGrains && !disableOrleansClustering && !string.IsNullOrEmpty(postgreSqlConnectionString) && isProduction) { siloBuilder.UseAdoNetReminderService(options => { @@ -131,8 +132,17 @@ public static class ApiBootstrap } else { - // Use basic endpoint configuration that works reliably in Docker - siloBuilder.ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000); + // Use localhost for development, proper hostname for production + if (isProduction) + { + // In production, use all interfaces + siloBuilder.ConfigureEndpoints(IPAddress.Any, 11111, 30000); + } + else + { + // In development, use localhost + siloBuilder.ConfigureEndpoints(IPAddress.Loopback, 11111, 30000); + } } siloBuilder @@ -202,9 +212,10 @@ public static class ApiBootstrap }); } - // Configure grain storage - use ADO.NET for production or memory for fallback - if (!disableOrleansClustering && !string.IsNullOrEmpty(postgreSqlConnectionString)) + // Configure grain storage - use ADO.NET for production or memory for development/fallback + if (!disableOrleansClustering && !string.IsNullOrEmpty(postgreSqlConnectionString) && isProduction) { + // Use ADO.NET storage in production siloBuilder .AddAdoNetGrainStorage("bot-store", options => { @@ -229,7 +240,7 @@ public static class ApiBootstrap } else { - // Fallback to memory storage when database is unavailable + // Use memory storage for development or when database is unavailable siloBuilder .AddMemoryGrainStorage("bot-store") .AddMemoryGrainStorage("registry-store")