From 57e65e5515f644393c5ef416fedc7ad56d4ab7f9 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 21 Mar 2022 01:52:32 +0100 Subject: [PATCH] Coordinator fix --- .../NadekoBot.Coordinator.csproj | 4 +- .../Services/CoordinatorRunner.cs | 48 +++++++++++-------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/NadekoBot.Coordinator/NadekoBot.Coordinator.csproj b/src/NadekoBot.Coordinator/NadekoBot.Coordinator.csproj index 47be7bad2..4497829e5 100644 --- a/src/NadekoBot.Coordinator/NadekoBot.Coordinator.csproj +++ b/src/NadekoBot.Coordinator/NadekoBot.Coordinator.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 @@ -9,7 +9,7 @@ - + diff --git a/src/NadekoBot.Coordinator/Services/CoordinatorRunner.cs b/src/NadekoBot.Coordinator/Services/CoordinatorRunner.cs index b89d09aec..08784f4f0 100644 --- a/src/NadekoBot.Coordinator/Services/CoordinatorRunner.cs +++ b/src/NadekoBot.Coordinator/Services/CoordinatorRunner.cs @@ -114,14 +114,6 @@ namespace NadekoBot.Coordinator StartShard(shardId); break; } - - if (status.Process is null or {HasExited: true}) - { - Log.Warning("Shard {ShardId} is starting (process)...", shardId); - hadAction = true; - StartShard(shardId); - break; - } if (DateTime.UtcNow - status.LastUpdate > TimeSpan.FromSeconds(_config.UnresponsiveSec)) @@ -139,6 +131,24 @@ namespace NadekoBot.Coordinator StartShard(shardId); break; } + + try + { + if (status.Process is null or { HasExited: true }) + { + Log.Warning("Shard {ShardId} is starting (process)...", shardId); + hadAction = true; + StartShard(shardId); + break; + } + } + catch (InvalidOperationException) + { + Log.Warning("Process for shard {ShardId} is bugged... ", shardId); + hadAction = true; + StartShard(shardId); + break; + } } } @@ -161,17 +171,13 @@ namespace NadekoBot.Coordinator var status = _shardStatuses[shardId]; try { - if (status.Process is { HasExited: false } p) - { - try - { - p.Kill(true); - } - catch - { - } - } - + status.Process?.Kill(true); + } + catch + { + } + try + { status.Process?.Dispose(); } catch @@ -282,8 +288,8 @@ namespace NadekoBot.Coordinator var status = _shardStatuses[shardId]; if (status.Process is { } p) { - p.Kill(); - p.Dispose(); + try{p.Kill();} catch {} + try{p.Dispose();} catch {} _shardStatuses[shardId] = status with { Process = null,