From 8baee13503649c5d627675b1e454367fad8e4ef6 Mon Sep 17 00:00:00 2001 From: xfy Date: Tue, 21 Apr 2026 11:41:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(proxy,config):=20=E4=BF=AE=E5=A4=8D=20Healt?= =?UTF-8?q?hChecker=20=E9=87=8D=E5=90=AF=E6=94=AF=E6=8C=81=E5=92=8C?= =?UTF-8?q?=E8=A1=A5=E5=85=85=20random=20=E7=AE=97=E6=B3=95=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stop 后重建 stopCh 以支持再次 Start;config 注释补充 random 算法。 Co-Authored-By: Claude Opus 4.7 --- internal/config/config.go | 2 +- internal/proxy/health.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/config/config.go b/internal/config/config.go index 593b474..82c4dc2 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -319,7 +319,7 @@ type StaticConfig struct { // 注意事项: // - Path 使用前缀匹配,较长路径优先匹配 // - 至少配置一个 Target 才能正常工作 -// - 负载均衡算法支持:round_robin、weighted_round_robin、least_conn、ip_hash、consistent_hash +// - 负载均衡算法支持:round_robin、weighted_round_robin、least_conn、ip_hash、consistent_hash、random // - 一致性哈希需要配置 HashKey // // 使用示例: diff --git a/internal/proxy/health.go b/internal/proxy/health.go index 07fd51d..9a9363e 100644 --- a/internal/proxy/health.go +++ b/internal/proxy/health.go @@ -120,11 +120,14 @@ func (h *HealthChecker) Start() { // Stop 停止后台健康检查进程。 // 它向后台 goroutine 发送停止信号并等待其完成。 // Stop 是幂等的;在已停止的检查器上调用它不会产生任何效果。 +// Stop 后可以再次调用 Start 重新启动检查器。 func (h *HealthChecker) Stop() { if !h.running.CompareAndSwap(true, false) { return // 已经停止,直接返回 } close(h.stopCh) + // 重新创建 stopCh 以支持后续 Start + h.stopCh = make(chan struct{}) } // run 是在后台 goroutine 中运行的主要健康检查循环。