Skip to content

fix(proxy): enforce SSE pending limit per event instead of per chunk - #9867

Merged
farion1231 merged 1 commit into
farion1231:mainfrom
HaiYangBG1:fix/sse-per-event-pending-limit
Nov 23, 2026
Merged

farion1231 merged 1 commit into
farion1231:mainfrom
HaiYangBG1:fix/sse-per-event-pending-limit

Conversation

@HaiYangBG1

Copy link
Copy Markdown
Contributor

Human Note / 本人说明

接 #9846 合并后维护者提到的边界问题(按整块算上限时,快满上限的正常事件和下一条同块到达会被误跳过)。改成只按当前事件到分隔符的长度判断,超限时只丢弃当前那条、保留前面已收尾的事件,并补回归测试。

Summary / 概述

  • Track the start of the current unterminated event (current_event_start) in SseBuffer when max_pending_bytes is enabled (keeping the unbounded SseBuffer::new() fast path untouched).
  • In SseBuffer::push_bytes and SseBuffer::push_str, scan for the next SSE event delimiter using SkipDelimiterState::from_pending(&self.text[self.current_event_start..], &self.utf8_remainder) and evaluate overflow against only the current event's bytes up to that delimiter instead of the entire incoming chunk.
  • On overflow, truncate only the current unterminated event (discard_current_event), shrink excess capacity, and clamp scan_from, preserving any valid complete events already buffered earlier in the same chunk; advance directly past the delimiter when it falls within the current chunk.
  • Add regression tests in src-tauri/src/proxy/sse.rs covering near-limit events sharing a chunk with subsequent events (all 4 LF/CRLF delimiter forms, every split point, multi-byte UTF-8, and push_str), preceding valid events preserved when a later event in the same chunk overflows, leading newlines/empty events across boundaries, and scan_from clamping with split \n/\r/\n recovery.

Related Issue / 关联 Issue

Follow-up to #9846

Screenshots / 截图

N/A

Checklist / 检查清单

  • pnpm typecheck passes / 通过 TypeScript 类型检查 (N/A — Rust-only change)
  • pnpm format:check passes / 通过代码格式检查 (N/A — Rust-only change)
  • cargo clippy passes (if Rust code changed) / 通过 Clippy 检查(如修改了 Rust 代码)
  • Updated i18n files if user-facing text changed / 如修改了用户可见文本,已更新国际化文件 (N/A — no user-facing text changed)

Verified locally:

  • cargo fmt --check --manifest-path src-tauri/Cargo.toml
  • cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings
  • cargo test --manifest-path src-tauri/Cargo.toml --lib proxy::sse::tests (20 passed)
  • cargo test --manifest-path src-tauri/Cargo.toml --lib proxy::response_processor::tests (19 passed)

@github-actions github-actions Bot added backend Backend (Rust/Tauri) proxy Related to proxy/API forwarding labels Nov 22, 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
farion1231 merged commit 84e4612 into farion1231:main Nov 23, 2026
10 checks passed
@farion1231

Copy link
Copy Markdown
Owner

已合并,感谢您的贡献!

上次合并 #9846 时提到的那个小问题,这么快就修好了。现在只按当前这条事件到分隔符的长度判断是否超限,同一块里前面已经完整的事件也不会被连带丢掉;测试覆盖了分隔符被拆开、多字节字符被切开和 push_str 这几种情况,把新测试放到旧实现上也确实会失败,回归锁很扎实。

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.

2 participants