Skip to content

[Bug/错误]: Anthropic 流式请求时 SSE 解码 goroutine 发生 panic,导致 AxonHub 进程崩溃 #1634

@yeluonight

Description

@yeluonight

Pre-submission Checklist / 提交前检查

  • I have searched the existing issues and this bug has not been reported / 我已搜索现有 issues,此 Bug 尚未被报告
  • I have read the documentation / 我已阅读文档
  • I am using the latest version of AxonHub / 我正在使用 AxonHub 的最新版本

FAQ Check / FAQ 检查

  • I have checked the FAQ and this bug is not covered there / 我已查阅 FAQ,此 Bug 未被覆盖

Bug Description / Bug 描述

AxonHub 在处理 Claude Code 发起的 Anthropic 流式请求时会崩溃。
触发场景是:Claude Code 正在通过 AxonHub 调用流式接口时,如果请求被取消、连接中断,或者上游流式响应提前关闭,AxonHub 仍然继续读取已经关闭的 SSE 流,结果触发空指针 panic,导致整个 AxonHub 进程退出。

核心错误:
panic: runtime error: invalid memory address or nil pointer dereference

崩溃位置:
github.com/looplj/axonhub/llm/httpclient.(*defaultSSEDecoder).Next
/build/llm/httpclient/decoder.go:95

github.com/looplj/axonhub/internal/server/orchestrator.(*ChatCompletionOrchestrator).Process.captureRawProviderStream.func15.1
/build/internal/server/orchestrator/pass_through.go:234

Steps to Reproduce / 复现步骤

使用 Claude Code 通过 AxonHub 调用 Anthropic 兼容接口:
POST /anthropic/v1/messages
使用流式输出。
在生成过程中取消请求、断开客户端,或者上游流式响应异常结束。
AxonHub 有概率直接崩溃,Docker 容器停止。
同时日志里有:
panic: runtime error: invalid memory address or nil pointer dereference

Expected Behavior / 期望行为

这次请求失败,但 AxonHub 服务继续运行,Docker 容器不停止。

Error Message / 错误消息

Operating System / 操作系统

Docker / Docker

AxonHub Version / AxonHub 版本

0.9.42

Usage Scenario / 使用场景

Claude Code

API Format / API 格式

Anthropic - Messages (/v1/messages) / Anthropic Messages

Channel Type / 渠道类型

Custom/Other / 自定义/其他

Logs / 日志

2026-05-10T13:02:41.717201164Z panic: runtime error: invalid memory address or nil pointer dereference
2026-05-10T13:02:41.717271016Z [signal SIGSEGV: segmentation violation code=0x1 addr=0x79 pc=0x54193a]

goroutine 399 [running]:
bufio.(*Scanner).Scan(0x3b7f7349c300?)
    /usr/local/go/src/bufio/scan.go:140 +0x1a
github.com/tmaxmax/go-sse/internal/parser.(*Parser).Next(0x3b7f7349ab40, 0x3b7f72d95c30)
    /go/pkg/mod/github.com/looplj/go-sse@v0.0.0-20250909130008-e74a1155bc3b/internal/parser/parser.go:60 +0x3a
github.com/tmaxmax/go-sse.(*Stream).Recv(0x3b7f7349e0e0)
    /go/pkg/mod/github.com/looplj/go-sse@v0.0.0-20250909130008-e74a1155bc3b/stream.go:49 +0xbf
github.com/looplj/axonhub/llm/httpclient.(*defaultSSEDecoder).Next(0x3b7f73463ae0)
    /build/llm/httpclient/decoder.go:95 +0xf7
github.com/looplj/axonhub/internal/server/orchestrator.(*ChatCompletionOrchestrator).Process.captureRawProviderStream.func15.1()
    /build/internal/server/orchestrator/pass_through.go:234 +0x138
created by github.com/looplj/axonhub/internal/server/orchestrator.(*ChatCompletionOrchestrator).Process.captureRawProviderStream.func15 in goroutine 94
    /build/internal/server/orchestrator/pass_through.go:219 +0x205

Additional Context / 其他补充信息

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions