Skip to content

fix: increase SSE scanner max line size from 40MB to 500MB#874

Merged
Wei-Shaw merged 2 commits intoWei-Shaw:mainfrom
touwaeriol:pr/increase-sse-max-line-size
Mar 9, 2026
Merged

fix: increase SSE scanner max line size from 40MB to 500MB#874
Wei-Shaw merged 2 commits intoWei-Shaw:mainfrom
touwaeriol:pr/increase-sse-max-line-size

Conversation

@touwaeriol
Copy link
Contributor

背景 / Background

通过 Gemini 生成 4K 分辨率图片时,上游响应中的 base64 数据行可能超过 40MB,导致 bufio.Scannertoken too long 错误,客户端收到空的 candidates。

When generating 4K resolution images via Gemini, the base64 data line in upstream SSE responses can exceed 40MB, causing bufio.Scanner to fail with token too long error. The client receives empty candidates as a result.


目的 / Purpose

将 SSE scanner 的最大行大小从 40MB 提升到 500MB,支持 4K 甚至 8K 图片的 base64 传输。bufio.Scanner 本身是自适应的(初始 64KB,按需增长),增大上限不会影响正常文本响应的内存使用。

Increase the SSE scanner max line size from 40MB to 500MB to support 4K and even 8K image base64 transfer. bufio.Scanner is adaptive (starts at 64KB, grows as needed), so increasing the cap has zero impact on memory usage for normal text responses.


改动内容 / Changes

后端 / Backend

  • gateway_service.godefaultMaxLineSize 常量从 40 * 1024 * 1024 改为 500 * 1024 * 1024
  • config.goviper.SetDefault("gateway.max_line_size", ...) 同步从 40MB 改为 500MB(viper 配置默认值会覆盖代码常量,两处必须同步修改)

  • gateway_service.go: Update defaultMaxLineSize constant from 40 * 1024 * 1024 to 500 * 1024 * 1024
  • config.go: Update viper.SetDefault("gateway.max_line_size", ...) from 40MB to 500MB (viper config default overrides the code constant, both must be updated in sync)

4K image base64 data can exceed 40MB limit, causing "bufio.Scanner:
token too long" errors. Scanner is adaptive (starts at 64KB, grows
as needed), so increasing the cap has no impact on normal responses.
The viper config default (config.go) was overriding the constant
in gateway_service.go. Both must be updated to take effect.
@touwaeriol touwaeriol force-pushed the pr/increase-sse-max-line-size branch from c794f7f to 4ce986d Compare March 9, 2026 00:57
@Wei-Shaw Wei-Shaw merged commit c74d451 into Wei-Shaw:main Mar 9, 2026
4 checks passed
@ztj7728
Copy link

ztj7728 commented Mar 10, 2026

gemini渠道已成功出图4K,但是反重力渠道仍然无法正常出图4K。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants