diff --git a/agent/main.go b/agent/main.go index 55b3c54..aa678aa 100644 --- a/agent/main.go +++ b/agent/main.go @@ -35,7 +35,7 @@ import ( ) var ( - version = "v2.2.0" + version = "v1.0.2" buildTime = "unknown" ) @@ -300,6 +300,12 @@ func main() { const minInterval = 5 * time.Second const fallbackConfigPollInterval = 30 * time.Second intervalUpdates := make(chan time.Duration, 1) + // appliedReportInterval 记录已生效的上报间隔(秒)。 + // 只在值真正变化时才下发重置信号:否则配置轮询每 30s 推一次相同值, + // ticker.Reset 会不断重新计时,导致 30s 的 ticker 永远等不到触发、 + // 上报被无形拖长到 60~90s。 // Logan.Li + appliedReportInterval := cfg.Interval + appliedConfigPollInterval := int(fallbackConfigPollInterval / time.Second) configTicker := time.NewTicker(fallbackConfigPollInterval) go func() { @@ -334,21 +340,24 @@ func main() { portCollector.SetPolicy(merged.PortPolicy) } - // 服务端下发的上报间隔 → 通知主循环热更新 ticker。 // Logan.Li - if merged.ReportInterval > 0 { + // 服务端下发的上报间隔 → 仅在值变化时通知主循环热更新 ticker。 // Logan.Li + if merged.ReportInterval > 0 && merged.ReportInterval != appliedReportInterval { next := time.Duration(merged.ReportInterval) * time.Second if next < minInterval { next = minInterval } + appliedReportInterval = merged.ReportInterval select { case intervalUpdates <- next: default: } } - // 服务端下发的配置轮询间隔 → 调整本循环节奏。 // Logan.Li - if merged.ConfigPollInterval > 0 { + // 服务端下发的配置轮询间隔 → 同样仅在值变化时重置, + // 否则每次轮询都 Reset 会让 ticker 永远不触发。 // Logan.Li + if merged.ConfigPollInterval > 0 && merged.ConfigPollInterval != appliedConfigPollInterval { next := time.Duration(merged.ConfigPollInterval) * time.Second - if next >= minInterval && next != fallbackConfigPollInterval { + if next >= minInterval { + appliedConfigPollInterval = merged.ConfigPollInterval configTicker.Reset(next) } }