fix(proxy): 完善备用补提与失败组暂停
- 备用不足不再触发活动代理池重建\n- 白名单 verify 限频错误保留消息并允许重试\n- 严格模式失败组暂停请求并持续补提取\n- 增加备用代理健康探测与运行门禁校验
This commit is contained in:
+15
-4
@@ -243,14 +243,25 @@ func (p *IPZanProvider) verifyWhitelist(ctx context.Context, httpClient *http.Cl
|
||||
return false, err
|
||||
}
|
||||
var payload struct {
|
||||
Code *int `json:"code"`
|
||||
Data json.RawMessage `json:"data"`
|
||||
Code *int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Info string `json:"info"`
|
||||
Msg string `json:"msg"`
|
||||
Data json.RawMessage `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &payload); err != nil {
|
||||
return false, fmt.Errorf("解析品赞白名单校验响应失败: %w", err)
|
||||
}
|
||||
if payload.Code == nil || *payload.Code != 0 {
|
||||
return false, &ProviderError{Provider: "品赞", Message: "白名单校验失败", Fatal: true}
|
||||
if payload.Code == nil {
|
||||
return false, fmt.Errorf("品赞白名单校验响应缺少 code: %s", truncateText(string(body), 120))
|
||||
}
|
||||
if *payload.Code != 0 {
|
||||
message := firstNonEmpty(payload.Message, payload.Info, payload.Msg, "品赞返回未知错误")
|
||||
return false, &ProviderError{
|
||||
Provider: "品赞",
|
||||
Message: "校验白名单失败: " + message,
|
||||
Fatal: isIPZanFatalMessage(message),
|
||||
}
|
||||
}
|
||||
var exists bool
|
||||
if json.Unmarshal(payload.Data, &exists) == nil {
|
||||
|
||||
@@ -310,3 +310,30 @@ func TestIPZanEnsureWhitelistSignsAndAdds(t *testing.T) {
|
||||
t.Fatal("whiteList-add was not called")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPZanWhitelistVerifyRateLimitIsRetryable(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/whiteList-verify" {
|
||||
t.Fatalf("unexpected path %s", r.URL.Path)
|
||||
}
|
||||
io.WriteString(w, `{"code":-1,"data":null,"status":200,"message":"白名单仅支持1秒访一次"}`)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
provider := &IPZanProvider{baseURL: server.URL, now: time.Now}
|
||||
_, err := provider.verifyWhitelist(
|
||||
context.Background(),
|
||||
server.Client(),
|
||||
"plan-no",
|
||||
"1.2.3.4",
|
||||
)
|
||||
if err == nil {
|
||||
t.Fatal("expected whitelist verify error")
|
||||
}
|
||||
if IsFatal(err) {
|
||||
t.Fatalf("rate limit should be retryable: %v", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "白名单仅支持1秒访一次") {
|
||||
t.Fatalf("provider message lost: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user