diff --git a/JoshHeaps.Net/Services/Implementations/Stockfish.cs b/JoshHeaps.Net/Services/Implementations/Stockfish.cs index bf2d3d9..3ba64ab 100644 --- a/JoshHeaps.Net/Services/Implementations/Stockfish.cs +++ b/JoshHeaps.Net/Services/Implementations/Stockfish.cs @@ -100,11 +100,26 @@ public sealed class Stockfish : IChessEngine if (line == token) break; } + // If Stockfish doesn't exit on "quit" (crashed, zombie, ignores stdin close), don't hang + // here forever — that would block GameStore's removal task and leave the finished game + // stuck in the store, cluttering the watch page indefinitely. + private static readonly TimeSpan _exitTimeout = TimeSpan.FromSeconds(5); + public async ValueTask DisposeAsync() { Send("quit"); _stdin.Close(); - await _p.WaitForExitAsync(); + + try + { + await _p.WaitForExitAsync().WaitAsync(_exitTimeout); + } + catch (TimeoutException) + { + if (!_p.HasExited) + _p.Kill(entireProcessTree: true); + } + _p.Dispose(); } }