Skip to content

Chat: stream error 시 reader.cancel() 호출 및 빈 응답 처리 개선 #142

Description

@blackdew

배경

PR #139에서 stream reader 경쟁 조건을 수정했으나, 에러 시 리소스 해제와 빈 응답 처리에 개선 여지가 있음.

수정 필요 사항

1. stream error 시 reader.cancel() 미호출

src/components/Chat/Root/Input/index.tsx:387-393, useChatProcess.tsx:151-157

// 현재: ref만 null 처리
catch (error) {
    chatLogger('readResponse stream error', error);
    if (readerRef.current === reader) {
        readerRef.current = null;
    }
    throw error;
}

// 개선: reader.cancel() 추가
catch (error) {
    chatLogger('readResponse stream error', error);
    await reader.cancel();
    if (readerRef.current === reader) {
        readerRef.current = null;
    }
    throw error;
}

2. null response body 시 빈 문자열 반환

src/components/Chat/Root/Input/index.tsx:342-344

if (!response.body) {
    chatLogger('readResponse: response.body is null');
    return '';  // 사용자에게 빈 AI 응답 표시 가능
}

빈 문자열 대신 사용자에게 에러 메시지를 표시하는 것이 나을 수 있음.

3. getSimilarity 무의미한 try-catch 제거

src/components/Chat/Root/Input/index.tsx:501-503

} catch (error) {
    throw error;  // 아무 동작 없이 re-throw
}

제거하거나 chatLogger 추가. 참고: useChatProcess.tsx의 동일 함수는 AbortError 처리가 있어 올바름.

관련 PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions