Skip to content

fix(proxy): 限制 SSE 转换器的单事件缓冲大小 - #9938

Merged
farion1231 merged 2 commits into
farion1231:mainfrom
wlndysky:fix/proxy-bound-sse-conversion
Nov 27, 2026
Merged

farion1231 merged 2 commits into
farion1231:mainfrom
wlndysky:fix/proxy-bound-sse-conversion

Conversation

@wlndysky

@wlndysky wlndysky commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

本人说明

我看了一下,SseBuffer 默认是不限制大小的。Gemini 转换器直接用了这个 buffer,只要没收到分隔符,它就会一直往里塞数据,内存就无限涨。

概述

代理转换或改写上游 SSE 时,对每个事件应用 64 MiB 上限。单个事件超限后,按转换后的协议返回错误并结束当前流;正常事件仍可跨数据块接收,同一个数据块也可包含多个事件。兼容普通 JSON 响应的转换路径会额外检查整份文档的大小。历史记录层遇到超限事件时只跳过记录,仍原样转发字节。

关联 Issue

Fixes #9937

截图

不适用(仅后端改动)。

验证

  • 22 项 SSE 分帧测试、196 项流式转换测试、77 项相关改写和历史记录测试通过。
  • Gemini 回归用例使用 32 字节的测试上限,验证超限后报错并停止读取。测试没有启动代理或访问上游。

检查清单

  • cargo fmt --check
  • cargo clippy --locked --offline --lib -- -D warnings
  • 前端检查和翻译不适用:本次没有前端改动。

Apply the existing per-event size budget to stream converters and rewriters.
Return a stream failure on overflow, bound JSON fallback documents, and cover the behavior with small in-memory inputs.
@github-actions github-actions Bot added documentation Improvements or additions to documentation backend Backend (Rust/Tauri) proxy Related to proxy/API forwarding labels Nov 24, 2026
@wlndysky wlndysky changed the title fix(proxy): bound upstream SSE conversion buffers fix(proxy): 限制 SSE 转换器的单事件缓冲大小 Nov 24, 2026

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,感谢您的贡献!

@farion1231

Copy link
Copy Markdown
Owner

已合并,感谢您的贡献!转换层补上这道上限后,和日志层的防护对齐了。合并前我把 main 合进了分支,顺手去掉了 CHANGELOG 里的 [Unreleased] 段(CHANGELOG 在发版时统一写),其余改动保持原样。

@github-actions github-actions Bot removed the documentation Improvements or additions to documentation label Nov 27, 2026
@farion1231
farion1231 merged commit 8b045ff into farion1231:main Nov 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend (Rust/Tauri) proxy Related to proxy/API forwarding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 本地代理的 SSE 转换器没有单事件大小上限

2 participants