Skip to content

Commit 06436d3

Browse files
committed
perf: 채팅 서비스 비동기 패턴 개선 및 예외 안전성 강화
Task.Run 내부에 예외 처리 추가로 관찰되지 않은 태스크 예외 방지 ConfigureAwait(false) 적용으로 컨텍스트 스위칭 최적화
1 parent da6c585 commit 06436d3

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

ProjectVG.Application/Services/Chat/ChatService.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public async Task<ChatRequestResult> EnqueueChatRequestAsync(ChatRequestCommand
7373
LogChatRequestCommand(command);
7474

7575
_ = Task.Run(async () => {
76-
await ProcessChatRequestInternalAsync(preprocessContext);
76+
await ProcessChatRequestInternalAsync(preprocessContext).ConfigureAwait(false);
7777
});
7878

7979
return ChatRequestResult.Accepted(command.Id.ToString(), command.UserId, command.CharacterId);
@@ -109,20 +109,18 @@ private async Task ProcessChatRequestInternalAsync(ChatProcessContext context)
109109
{
110110
using var scope = _scopeFactory.CreateScope();
111111
try {
112-
await _llmProcessor.ProcessAsync(context);
113-
await _ttsProcessor.ProcessAsync(context);
112+
await _llmProcessor.ProcessAsync(context).ConfigureAwait(false);
113+
await _ttsProcessor.ProcessAsync(context).ConfigureAwait(false);
114114

115-
// ChatSuccessHandler와 ChatResultProcessor를 같은 스코프에서 실행
116-
117115
var successHandler = scope.ServiceProvider.GetRequiredService<ChatSuccessHandler>();
118116
var resultProcessor = scope.ServiceProvider.GetRequiredService<ChatResultProcessor>();
119-
120-
await successHandler.HandleAsync(context);
121-
await resultProcessor.PersistResultsAsync(context);
117+
118+
await successHandler.HandleAsync(context).ConfigureAwait(false);
119+
await resultProcessor.PersistResultsAsync(context).ConfigureAwait(false);
122120
}
123121
catch (Exception) {
124122
var failureHandler = scope.ServiceProvider.GetRequiredService<ChatFailureHandler>();
125-
await failureHandler.HandleAsync(context);
123+
await failureHandler.HandleAsync(context).ConfigureAwait(false);
126124
}
127125
finally {
128126
LogChatProcessContext(context);

0 commit comments

Comments
 (0)