2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2026-06-13 22:48:42 +00:00

Close fanout sweep subscriber connections

This commit is contained in:
2026-06-04 18:45:11 +03:00
parent d626bdb1ba
commit 25d7449d44
@@ -124,7 +124,9 @@ foreach (int n in nValues)
bool spawnFailed = false; bool spawnFailed = false;
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
{ {
if (spawnTasks[i].Result == null) { spawnFailed = true; break; } if (spawnTasks[i].Result == null)
spawnFailed = true;
else
subscribers[i] = spawnTasks[i].Result!; subscribers[i] = spawnTasks[i].Result!;
} }
spawnSw.Stop(); spawnSw.Stop();
@@ -133,7 +135,7 @@ foreach (int n in nValues)
{ {
Console.WriteLine($"[Orchestrator] N={n}: spawn failed; treating as saturation."); Console.WriteLine($"[Orchestrator] N={n}: spawn failed; treating as saturation.");
saturatedDetected = true; saturatedDetected = true;
await TeardownAll(subscriberWhs); await TeardownAll(subscribers, subscriberWhs);
break; break;
} }
Console.WriteLine($"[Orchestrator] All {n} subscribers attached in {spawnSw.Elapsed.TotalSeconds:F2}s"); Console.WriteLine($"[Orchestrator] All {n} subscribers attached in {spawnSw.Elapsed.TotalSeconds:F2}s");
@@ -229,7 +231,7 @@ foreach (int n in nValues)
// ---------- teardown ---------- // ---------- teardown ----------
Console.WriteLine($"[Orchestrator] Tearing down {n} subscribers..."); Console.WriteLine($"[Orchestrator] Tearing down {n} subscribers...");
await TeardownAll(subscriberWhs); await TeardownAll(subscribers, subscriberWhs);
await Task.Delay(settleSec * 1000); await Task.Delay(settleSec * 1000);
} }
@@ -298,7 +300,7 @@ static async Task<SubscriberTask?> SpawnSubscriber(
try try
{ {
var conn = await wh.Get<EpConnection>($"ep://{host}:{port}"); var conn = await wh.Get<EpConnection>($"ep://{host}:{port}");
var sub = new SubscriberTask { SubscriberId = subId }; var sub = new SubscriberTask { SubscriberId = subId, Connection = conn };
for (int i = 0; i < resources; i++) for (int i = 0; i < resources; i++)
{ {
@@ -326,8 +328,20 @@ static async Task<SubscriberTask?> SpawnSubscriber(
} }
} }
static async Task TeardownAll(Warehouse[] whs) static async Task TeardownAll(SubscriberTask[] subscribers, Warehouse[] whs)
{ {
foreach (var subscriber in subscribers)
{
if (subscriber == null)
continue;
try { subscriber.Connection?.Close(); }
catch { /* ignore */ }
subscriber.Connection = null;
subscriber.Resources.Clear();
}
foreach (var wh in whs) foreach (var wh in whs)
{ {
try { await wh.Close(); } try { await wh.Close(); }
@@ -386,6 +400,7 @@ static string GetArg(string[] args, string key, string def)
class SubscriberTask class SubscriberTask
{ {
public int SubscriberId; public int SubscriberId;
public EpConnection? Connection;
public readonly List<IResource> Resources = new(); public readonly List<IResource> Resources = new();
internal long _received; internal long _received;
internal long _lateDeliveries; internal long _lateDeliveries;