fix(chat): 修复 SSE 流异常处理导致的二次错误 - #113
Open
IfYou66 wants to merge 1 commit into
Open
Conversation
IfYou66
force-pushed
the
lym/fix-sse-error-handling
branch
from
August 13, 2026 02:09
6b19cc8 to
a2a4862
Compare
IfYou66
marked this pull request as ready for review
August 13, 2026 02:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题背景
流式对话发生业务异常时,当前逻辑会调用
SseEmitter.completeWithError()。该方法会触发一次异步错误分发。由于响应类型已经被设置为
text/event-stream,后续全局异常处理返回的普通 JSON 响应无法按照 SSE 类型写出,进而产生HttpMessageNotWritableException等二次异常。与此同时,前端无法收到已经支持的
errorSSE 事件,只能感知到连接异常结束。修复内容
error事件类型。error事件;complete()正常结束 SSE 响应。IOException时,仅标记连接关闭,不再调用completeWithError(),避免触发二次错误分发。影响范围
本次修改仅影响流式对话的异常结束路径。
正常消息、思考过程、完成事件、取消事件及队列限流逻辑保持不变。
测试
相关测试类共 4 个,全部通过:
SseEmitterSenderTestcompleteWithError()。StreamChatEventHandlerTesterrorSSE 事件。StreamChatPipelineTestChatQueueLimiterTest