Skip to content

Commit c0879a1

Browse files
committed
fix: 处理ws异步任务异常
1 parent fd7a2ce commit c0879a1

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Cyaim.WebSocketServer/Cyaim.WebSocketServer/Infrastructure/Handlers/MvcHandler/MvcChannelHandler.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,18 @@ await bandwidthLimitManager.WaitForBandwidthAsync(
592592
{
593593
await forwardTask;
594594
}
595+
else
596+
{
597+
// 无论是否串行,都处理 Task 异常(关键)
598+
forwardTask = forwardTask.ContinueWith(t =>
599+
{
600+
if (t.IsFaulted)
601+
{
602+
// 记录异常日志,避免未观察到的异常
603+
logger.LogInformation(t.Exception, t.Exception.Message, Encoding.UTF8.GetString(wsReceiveReader.GetBuffer()));
604+
}
605+
}, TaskContinuationOptions.OnlyOnFaulted);
606+
}
595607

596608
// 执行管道 AfterForwardingData
597609
_ = await InvokePipeline(RequestPipelineStage.AfterForwardingData, PipelineContext.CreateForward(context, webSocket, result, wsReceiveReader.GetBuffer(), requestScheme, requestBody, webSocketOption));

0 commit comments

Comments
 (0)