命中限流之后, 无视重试配置,不进行任何重试

This commit is contained in:
2025-04-16 20:59:52 +08:00
parent dbd9ab31a1
commit 60dd279663
4 changed files with 19 additions and 122 deletions

View File

@ -272,7 +272,10 @@ func (hc *HttpClient) requestBackendApi() *define.Response {
response.RequestCount++
if response.RestyResponse, err = hc.request.Send(); nil != err {
errType := define.RequestFailTypeSend
if _, ok := err.(net.Error); ok {
if err.Error() == resty.ErrRateLimitExceeded.Error() {
// 命中限流
errType = define.RequestFailTypeRateLimit
} else if _, ok := err.(net.Error); ok {
// 请求超时
errType = define.RequestFailTypeTimeoutError
}
@ -280,6 +283,10 @@ func (hc *HttpClient) requestBackendApi() *define.Response {
Type: errType,
Message: err.Error(),
}
if errType == define.RequestFailTypeSend {
// 命中限流就不重试了
break
}
time.Sleep(time.Duration(hc.reqConfig.RetryRule.RetryTimeInterval) * time.Millisecond)
continue
}

View File

@ -64,6 +64,7 @@ type ResponseCacheInfo struct {
}
const (
RequestFailTypeRateLimit = "SEND_REQUEST_RATE_LIMIT" // 发送请求即失败, 命中限流
RequestFailTypeSend = "SEND_REQUEST_FAIL" // 发送请求即失败, 问题出现在客户端
RequestFailTypeClientRequestInvalidError = "CLIENT_REQUEST_INVALID" // 请求非法
RequestFailTypeTimeoutError = "CLIENT_REQUEST_TIMEOUT_ERROR" // 请求失败, 请求超时