Merge pull request 'Time out Stockfish process exit so finished self-play games cant wedge in the store' (#8) from fix/stockfish-dispose-hang into master
Build and Deploy / build-deploy (push) Successful in 1m18s
Build and Deploy / build-deploy (push) Successful in 1m18s
Reviewed-on: #8
This commit was merged in pull request #8.
This commit is contained in:
@@ -100,11 +100,26 @@ public sealed class Stockfish : IChessEngine
|
|||||||
if (line == token) break;
|
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()
|
public async ValueTask DisposeAsync()
|
||||||
{
|
{
|
||||||
Send("quit");
|
Send("quit");
|
||||||
_stdin.Close();
|
_stdin.Close();
|
||||||
await _p.WaitForExitAsync();
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _p.WaitForExitAsync().WaitAsync(_exitTimeout);
|
||||||
|
}
|
||||||
|
catch (TimeoutException)
|
||||||
|
{
|
||||||
|
if (!_p.HasExited)
|
||||||
|
_p.Kill(entireProcessTree: true);
|
||||||
|
}
|
||||||
|
|
||||||
_p.Dispose();
|
_p.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user