204848 commited on
Commit
804f0ba
·
1 Parent(s): e358bb0

feat: 增强HIF轮询逻辑,添加退避饱和状态处理,优化日志记录

Browse files
Files changed (1) hide show
  1. internal/deepseek/hif/hif.go +16 -3
internal/deepseek/hif/hif.go CHANGED
@@ -75,6 +75,9 @@ func (p *HIFPoller) GetHeaders() map[string]string {
75
 
76
  func (p *HIFPoller) pollLoop(kind, url string) {
77
  interval := initialInterval
 
 
 
78
  for {
79
  select {
80
  case <-p.stopCh:
@@ -84,15 +87,20 @@ func (p *HIFPoller) pollLoop(kind, url string) {
84
 
85
  value, ttl, err := p.query(url)
86
  if err != nil {
87
- config.Logger.Warn("[hif] query failed", "kind", kind, "error", err, "retry_after", interval)
 
 
 
 
88
  select {
89
  case <-p.stopCh:
90
  return
91
  case <-time.After(interval):
92
  }
93
  interval = time.Duration(float64(interval) * float64(backoffFactor))
94
- if interval > maxInterval {
95
  interval = maxInterval
 
96
  }
97
  continue
98
  }
@@ -107,7 +115,12 @@ func (p *HIFPoller) pollLoop(kind, url string) {
107
  }
108
  p.mu.Unlock()
109
 
110
- config.Logger.Info("[hif] query success", "kind", kind, "ttl", ttl)
 
 
 
 
 
111
  interval = initialInterval
112
 
113
  sleepDuration := time.Duration(ttl) * time.Second
 
75
 
76
  func (p *HIFPoller) pollLoop(kind, url string) {
77
  interval := initialInterval
78
+ // saturated 标记退避是否已达到 maxInterval。达到后持续重试但降级日志,
79
+ // 避免在长期不可达环境(如 HF Spaces 无 IPv6 出口)刷屏;一旦成功即重置。
80
+ saturated := false
81
  for {
82
  select {
83
  case <-p.stopCh:
 
87
 
88
  value, ttl, err := p.query(url)
89
  if err != nil {
90
+ if saturated {
91
+ config.Logger.Debug("[hif] query failed (backoff saturated, retrying quietly)", "kind", kind, "error", err, "retry_after", interval)
92
+ } else {
93
+ config.Logger.Warn("[hif] query failed", "kind", kind, "error", err, "retry_after", interval)
94
+ }
95
  select {
96
  case <-p.stopCh:
97
  return
98
  case <-time.After(interval):
99
  }
100
  interval = time.Duration(float64(interval) * float64(backoffFactor))
101
+ if interval >= maxInterval {
102
  interval = maxInterval
103
+ saturated = true
104
  }
105
  continue
106
  }
 
115
  }
116
  p.mu.Unlock()
117
 
118
+ if saturated {
119
+ config.Logger.Info("[hif] query recovered after backoff saturation", "kind", kind, "ttl", ttl)
120
+ saturated = false
121
+ } else {
122
+ config.Logger.Info("[hif] query success", "kind", kind, "ttl", ttl)
123
+ }
124
  interval = initialInterval
125
 
126
  sleepDuration := time.Duration(ttl) * time.Second