diff --git a/src/Aiursoft.ChessServer/Controllers/GamesController.cs b/src/Aiursoft.ChessServer/Controllers/GamesController.cs index 7b1c9bf..f9ce6be 100644 --- a/src/Aiursoft.ChessServer/Controllers/GamesController.cs +++ b/src/Aiursoft.ChessServer/Controllers/GamesController.cs @@ -66,7 +66,14 @@ public class GamesController : Controller subscription = channel.Subscribe(async t => { await _pusher.SendMessage(t.Content); }); while (_pusher.Connected) { - await Task.Delay(10 * 1000); + try + { + await Task.Delay(int.MaxValue, HttpContext.RequestAborted); + } + catch (TaskCanceledException) + { + break; + } } } finally @@ -114,6 +121,7 @@ public class GamesController : Controller { return BadRequest(); } + game.Move(move); var fen = game.ToFen(); var channel = _database.GetOrAddChannel(id); diff --git a/src/Aiursoft.ChessServer/Services/WebSocketPusher.cs b/src/Aiursoft.ChessServer/Services/WebSocketPusher.cs index 8af3cdd..31ab75c 100644 --- a/src/Aiursoft.ChessServer/Services/WebSocketPusher.cs +++ b/src/Aiursoft.ChessServer/Services/WebSocketPusher.cs @@ -18,7 +18,14 @@ public class WebSocketPusher : IScopedDependency public async Task SendMessage(string message) { - await (_ws?.SendMessage(message) ?? throw new InvalidOperationException("WebSocket is not connected!")); + try + { + await (_ws?.SendMessage(message) ?? throw new InvalidOperationException("WebSocket is not connected!")); + } + catch (WebSocketException) + { + _dropped = true; + } } public async Task PendingClose()