add websocket timeouts

This commit is contained in:
uwaa 2024-11-15 15:22:00 +00:00
parent a41c46175b
commit b8b2c4a7c8

View file

@ -104,12 +104,13 @@ static class Program
static async Task<CloseStatus> HandleWebsocket(Websocket ws) static async Task<CloseStatus> HandleWebsocket(Websocket ws)
{ {
DataFrame payload = await ws.Read(); TimeSpan timeout = TimeSpan.FromMinutes(1);
DataFrame payload = await ws.Read().WaitAsync(timeout);
if (payload.Opcode != WSOpcode.Close) if (payload.Opcode != WSOpcode.Close)
{ {
string result = payload.AsString(); string result = payload.AsString();
await ws.Write($"Echoing message: \"{result}\""); await ws.Write($"Echoing message: \"{result}\"").WaitAsync(timeout);
} }
return CloseStatus.NormalClosure; return CloseStatus.NormalClosure;