Compare commits
3 Commits
1.5.9branc
...
v1.5.13
| Author | SHA1 | Date | |
|---|---|---|---|
| 888923c6ce | |||
| e496f8fb7e | |||
| fda016d011 |
@@ -1,7 +1,4 @@
|
|||||||
## Version 1.5.9
|
## Version 1.5.13
|
||||||
|
|
||||||
### Bugfix
|
### Bugfix
|
||||||
- Refactored clients to fix the problems with retries
|
- Fix EOF error by closing request
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
43
client.go
43
client.go
@@ -140,24 +140,37 @@ func (dc *DecortClient) do(req *http.Request) (*http.Response, error) {
|
|||||||
req.Header.Add("Authorization", "bearer "+dc.cfg.Token)
|
req.Header.Add("Authorization", "bearer "+dc.cfg.Token)
|
||||||
req.Header.Set("Accept", "application/json")
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
// var resp *http.Response
|
|
||||||
// var err error
|
|
||||||
buf, _ := io.ReadAll(req.Body)
|
buf, _ := io.ReadAll(req.Body)
|
||||||
|
|
||||||
// for i := uint64(0); i < dc.cfg.Retries; i++ {
|
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||||
// req = req.Clone(req.Context())
|
resp, err := dc.client.Do(req)
|
||||||
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
req.Close = true
|
||||||
resp, err := dc.client.Do(req)
|
if err != nil || resp == nil {
|
||||||
|
if strings.Contains(err.Error(), "connection reset by peer") {
|
||||||
// if err == nil {
|
|
||||||
if resp.StatusCode == 200 {
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
respBytes, _ := io.ReadAll(resp.Body)
|
|
||||||
err = fmt.Errorf("%s", respBytes)
|
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
// }
|
for i := uint64(0); i < dc.cfg.Retries; i++ {
|
||||||
// }
|
time.Sleep(5 * time.Second)
|
||||||
|
resp, err = dc.client.Do(req)
|
||||||
|
if strings.Contains(err.Error(), "connection reset by peer") {
|
||||||
|
resp.Body.Close()
|
||||||
|
continue
|
||||||
|
} else if err == nil {
|
||||||
|
break
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
respBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
err = fmt.Errorf("%s", respBytes)
|
||||||
|
resp.Body.Close()
|
||||||
|
|
||||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,18 +142,36 @@ func (ldc *LegacyDecortClient) do(req *http.Request) (*http.Response, error) {
|
|||||||
buf, _ := io.ReadAll(req.Body)
|
buf, _ := io.ReadAll(req.Body)
|
||||||
|
|
||||||
// for i := uint64(0); i < ldc.cfg.Retries; i++ {
|
// for i := uint64(0); i < ldc.cfg.Retries; i++ {
|
||||||
// req = req.Clone(req.Context())
|
// req = req.Clone(req.Context())
|
||||||
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||||
resp, err := ldc.client.Do(req)
|
resp, err := ldc.client.Do(req)
|
||||||
|
req.Close = true
|
||||||
// if err == nil {
|
if err != nil || resp == nil {
|
||||||
if resp.StatusCode == 200 {
|
if strings.Contains(err.Error(), "connection reset by peer") {
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
respBytes, _ := io.ReadAll(resp.Body)
|
|
||||||
err = fmt.Errorf("%s", respBytes)
|
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
// }
|
for i := uint64(0); i < ldc.cfg.Retries; i++ {
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
resp, err = ldc.client.Do(req)
|
||||||
|
if strings.Contains(err.Error(), "connection reset by peer") {
|
||||||
|
resp.Body.Close()
|
||||||
|
continue
|
||||||
|
} else if err == nil {
|
||||||
|
break
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
respBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
err = fmt.Errorf("%s", respBytes)
|
||||||
|
resp.Body.Close()
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user