From afcbc7e7498dc04aa3812e49d68acf71ce020880 Mon Sep 17 00:00:00 2001 From: Nikita Sorokin Date: Thu, 14 Sep 2023 15:05:38 +0300 Subject: [PATCH] 1.6.0-beta --- CHANGELOG.md | 6 ++---- internal/client/http-client.go | 2 ++ internal/client/legacy-http-client.go | 2 ++ internal/client/legacy-transport.go | 4 ++++ internal/client/transport.go | 5 +++++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea82860..97bab99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,4 @@ -## Version 1.5.7 +## Version 1.6.0-beta ### Bugfix -- Remove the required tag of the start field in the CreateRequest model in cb/lb/create, since it is impossible to create an lb without starting it -- Fix model the RecordGrid, add the ItemGridList model to cloudbroker/grid/models to correctly receive information on get and list requests -- Fix tag json field GID in model RecordResourcesConsumption cb/grid/models \ No newline at end of file +- Fixed RoudTrip bug in HTTP transport, made it concurrent safe \ No newline at end of file diff --git a/internal/client/http-client.go b/internal/client/http-client.go index d895df9..82c18cf 100644 --- a/internal/client/http-client.go +++ b/internal/client/http-client.go @@ -3,6 +3,7 @@ package client import ( "crypto/tls" "net/http" + "sync" "time" "repository.basistech.ru/BASIS/decort-golang-sdk/config" @@ -32,6 +33,7 @@ func NewHttpClient(cfg config.Config) *http.Client { ssoURL: cfg.SSOURL, token: cfg.Token, expiryTime: expiredTime, + mutex: &sync.Mutex{}, //TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, }, diff --git a/internal/client/legacy-http-client.go b/internal/client/legacy-http-client.go index 123df0c..c870d08 100644 --- a/internal/client/legacy-http-client.go +++ b/internal/client/legacy-http-client.go @@ -4,6 +4,7 @@ import ( "crypto/tls" "net/http" "net/url" + "sync" "time" "repository.basistech.ru/BASIS/decort-golang-sdk/config" @@ -33,6 +34,7 @@ func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client { token: cfg.Token, decortURL: cfg.DecortURL, expiryTime: expiredTime, + mutex: &sync.Mutex{}, }, Timeout: cfg.Timeout.Get(), diff --git a/internal/client/legacy-transport.go b/internal/client/legacy-transport.go index d2ddd1b..de705a0 100644 --- a/internal/client/legacy-transport.go +++ b/internal/client/legacy-transport.go @@ -5,6 +5,7 @@ import ( "io" "net/http" "strings" + "sync" "time" ) @@ -15,6 +16,7 @@ type transportLegacy struct { retries uint64 token string decortURL string + mutex *sync.Mutex expiryTime time.Time } @@ -56,7 +58,9 @@ func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, erro var resp *http.Response var err error for i := uint64(0); i < t.retries; i++ { + t.mutex.Lock() resp, err = t.base.RoundTrip(req) + t.mutex.Unlock() if err == nil { if resp.StatusCode == 200 { return resp, nil diff --git a/internal/client/transport.go b/internal/client/transport.go index 52a1aa4..d159de3 100644 --- a/internal/client/transport.go +++ b/internal/client/transport.go @@ -5,6 +5,7 @@ import ( "io" "net/http" "strings" + "sync" "time" ) @@ -16,6 +17,7 @@ type transport struct { token string ssoURL string expiryTime time.Time + mutex *sync.Mutex } func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { @@ -53,7 +55,9 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { var resp *http.Response var err error for i := uint64(0); i < t.retries; i++ { + t.mutex.Lock() resp, err = t.base.RoundTrip(req) + t.mutex.Unlock() if err == nil { if resp.StatusCode == 200 { return resp, nil @@ -65,5 +69,6 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { //logrus.Errorf("Could not execute request: %v. Retrying %d/%d", err, i+1, t.retries) time.Sleep(time.Second * 5) } + return nil, fmt.Errorf("could not execute request: %w", err) }