0x01 问题描述
在go项目中,使用 resty 。在http请求中,添加重试条件,在满足条件时才可以重试。使用中,后端所连的服务突然挂线,导致端口不存在,进而引发 connect refused 的错误。而又由于设置超时时间为 30s,导致在服务器响应前,请求方已经断开而报超时的问题。
0x02 代码片断
var client = resty.New()
func init() {
client.SetRetryCount(5)
client.SetTLSClientConfig(&tls.Config{
InsecureSkipVerify: true})
client.SetRetryWaitTime(time.Second * time.Duration(2))
client.AddRetryCondition(func(response *resty.Response) (b bool, err error) {
if response == nil || response.StatusCode() == 0 || (response.StatusCode() >= http.StatusLocked && response