From e496f8fb7e881a65779588c045b3c16d189cc0d8 Mon Sep 17 00:00:00 2001 From: Sergey Kisil Date: Thu, 30 Nov 2023 10:55:00 +0300 Subject: [PATCH] v1.5.12 --- CHANGELOG.md | 2 +- client.go | 15 +++++++++++++++ legacy-client.go | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca08282..f326172 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## Version 1.5.11 +## Version 1.5.12 ### Bugfix - Fix unhandled error in do() method for client and legacy-client diff --git a/client.go b/client.go index 7c2f9c4..30433f4 100644 --- a/client.go +++ b/client.go @@ -149,6 +149,21 @@ func (dc *DecortClient) do(req *http.Request) (*http.Response, error) { req.Body = io.NopCloser(bytes.NewBuffer(buf)) resp, err := dc.client.Do(req) if err != nil || resp == nil { + if strings.Contains(err.Error(),"connection reset by peer") { + 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 } diff --git a/legacy-client.go b/legacy-client.go index d2917c7..bdbcd3e 100644 --- a/legacy-client.go +++ b/legacy-client.go @@ -146,6 +146,21 @@ func (ldc *LegacyDecortClient) do(req *http.Request) (*http.Response, error) { req.Body = io.NopCloser(bytes.NewBuffer(buf)) resp, err := ldc.client.Do(req) if err != nil || resp == nil { + if strings.Contains(err.Error(),"connection reset by peer") { + 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 }