From d347d2a648fca737afd614dd0cf60a1134766a9b Mon Sep 17 00:00:00 2001 From: JianFeeeee Date: Tue, 6 Oct 2026 12:45:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(cluster):=20=E6=8A=8A=20balancer=20?= =?UTF-8?q?=E7=9C=9F=E7=9A=84=E6=8E=A5=E8=BF=9B=20Handler=EF=BC=88?= =?UTF-8?q?=E7=AB=AF=E7=82=B9=E6=AD=A4=E5=89=8D=20404=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上一提交注册了 /cluster/balance 并加了 Handler.Balancer 字段,但构造 Handler 时 忘了赋值 —— 端点因 h.Balancer == nil 走 404 分支。 单测发现不了:它们直接构造 Balancer 调 Report(),从不经过 HTTP 层。 canary 实跑抓到:端点 404(无认证倒是正确 401)。修好后同一 canary 返回 200, 字段齐全、默认 dryRun=true、单节点自认 leader、wouldMigrate 为空。 教训:单元测试覆盖不到"接线",凡新增端点必须真的起进程打过一次。 --- cmd/webui4frpc/main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/webui4frpc/main.go b/cmd/webui4frpc/main.go index 6745449..b66804a 100644 --- a/cmd/webui4frpc/main.go +++ b/cmd/webui4frpc/main.go @@ -402,6 +402,9 @@ func main() { Sessions: httpapi.NewSessionStore(), Cluster: reg, Ring: ring, + // Balancer is created above, before the environment that configures it is + // parsed, because the HTTP layer needs the pointer. + Balancer: balancer, // SelfAddr must be reachable by peers. 0.0.0.0/empty on a real host // would break peer reconnect, so fall back to the hostname (container // name inside docker is a routable addr on the compose network).