From c6db71bd7cb4225512665c14d7638aafb6db457f Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 13 Mar 2025 14:52:56 +0000 Subject: [PATCH 1/4] removed mutex --- httpclient/timeouts.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/httpclient/timeouts.go b/httpclient/timeouts.go index c228797..c36fbfd 100644 --- a/httpclient/timeouts.go +++ b/httpclient/timeouts.go @@ -1,22 +1,15 @@ package httpclient import ( - "sync" "time" ) -var mu sync.Mutex - // Amends the HTTP timeout time func (c *Client) ModifyHttpTimeout(newTimeout time.Duration) { - mu.Lock() - defer mu.Unlock() c.http.Timeout = newTimeout } // Resets HTTP timeout time back to 10 seconds func (c *Client) ResetTimeout() { - mu.Lock() - defer mu.Unlock() c.http.Timeout = DefaultTimeout } From edb6897b33b9c98200873c2c3d181ed0787fbf2a Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 13 Mar 2025 15:10:08 +0000 Subject: [PATCH 2/4] added get timeout --- httpclient/timeouts.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/httpclient/timeouts.go b/httpclient/timeouts.go index c36fbfd..8fb8371 100644 --- a/httpclient/timeouts.go +++ b/httpclient/timeouts.go @@ -13,3 +13,7 @@ func (c *Client) ModifyHttpTimeout(newTimeout time.Duration) { func (c *Client) ResetTimeout() { c.http.Timeout = DefaultTimeout } + +func (c *Client) HttpTimeout() time.Duration { + return c.http.Timeout +} From 7f2d380798dc520cd2d24a2fe81d89f52428424d Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 13 Mar 2025 16:04:29 +0000 Subject: [PATCH 3/4] added a debug log ' --- httpclient/multipartrequest.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/httpclient/multipartrequest.go b/httpclient/multipartrequest.go index 9b5c60c..d58bb14 100644 --- a/httpclient/multipartrequest.go +++ b/httpclient/multipartrequest.go @@ -80,6 +80,8 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][] var ctx context.Context var cancel context.CancelFunc + c.Sugar.Debugf("TIMEOUT: %v", c.config.CustomTimeout) + if c.config.CustomTimeout > 0 { ctx, cancel = context.WithTimeout(context.Background(), c.config.CustomTimeout) c.Sugar.Infow("Using timeout context for multipart request", zap.Duration("custom_timeout_seconds", c.config.CustomTimeout)) From 7021984674b15c2e6289dbbbb7a8be86472dffee Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 13 Mar 2025 16:21:37 +0000 Subject: [PATCH 4/4] added timeout back --- httpclient/client.go | 10 +++++----- httpclient/config_validation.go | 6 +++--- httpclient/multipartrequest.go | 8 +++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/httpclient/client.go b/httpclient/client.go index c301c52..01d1ca2 100644 --- a/httpclient/client.go +++ b/httpclient/client.go @@ -55,7 +55,7 @@ type ClientConfig struct { EnableDynamicRateLimiting bool `json:"enable_dynamic_rate_limiting"` // CustomTimeout // TODO also because I don't know. - CustomTimeout time.Duration + Timeout time.Duration // TokenRefreshBufferPeriod is the duration of time before the token expires in which it's deemed // more sensible to replace the token rather then carry on using it. @@ -107,12 +107,12 @@ func (c *ClientConfig) Build() (*Client, error) { httpClient := c.HTTP - if c.CustomTimeout == 0 { - c.CustomTimeout = DefaultTimeout + if c.Timeout == 0 { + httpClient.Timeout = DefaultTimeout + } else { + httpClient.Timeout = c.Timeout } - httpClient.Timeout = c.CustomTimeout - cookieJar, err := cookiejar.New(nil) if err != nil { return nil, err diff --git a/httpclient/config_validation.go b/httpclient/config_validation.go index 00c8b49..f0b285a 100644 --- a/httpclient/config_validation.go +++ b/httpclient/config_validation.go @@ -66,7 +66,7 @@ func LoadConfigFromEnv() (*ClientConfig, error) { MaxRetryAttempts: getEnvAsInt("MAX_RETRY_ATTEMPTS", DefaultMaxRetryAttempts), MaxConcurrentRequests: getEnvAsInt("MAX_CONCURRENT_REQUESTS", DefaultMaxConcurrentRequests), EnableDynamicRateLimiting: getEnvAsBool("ENABLE_DYNAMIC_RATE_LIMITING", DefaultEnableDynamicRateLimiting), - CustomTimeout: getEnvAsDuration("CUSTOM_TIMEOUT", DefaultCustomTimeout), + Timeout: getEnvAsDuration("CUSTOM_TIMEOUT", DefaultCustomTimeout), TokenRefreshBufferPeriod: getEnvAsDuration("TOKEN_REFRESH_BUFFER_PERIOD", DefaultTokenRefreshBufferPeriod), TotalRetryDuration: getEnvAsDuration("TOTAL_RETRY_DURATION", DefaultTotalRetryDuration), EnableConcurrencyManagement: getEnvAsBool("ENABLE_CONCURRENCY_MANAGEMENT", DefaultEnableConcurrencyManagement), @@ -111,7 +111,7 @@ func (c ClientConfig) validateClientConfig() error { } } - if c.CustomTimeout.Seconds() < 0 { + if c.Timeout.Seconds() < 0 { return errors.New("timeout cannot be less than 0 seconds") } @@ -139,7 +139,7 @@ func (c *ClientConfig) SetDefaultValuesClientConfig() { setDefaultInt(&c.MaxRetryAttempts, DefaultMaxRetryAttempts, 1) setDefaultInt(&c.MaxConcurrentRequests, DefaultMaxConcurrentRequests, 1) setDefaultBool(&c.EnableDynamicRateLimiting, DefaultEnableDynamicRateLimiting) - setDefaultDuration(&c.CustomTimeout, DefaultCustomTimeout) + setDefaultDuration(&c.Timeout, DefaultCustomTimeout) setDefaultDuration(&c.TokenRefreshBufferPeriod, DefaultTokenRefreshBufferPeriod) setDefaultDuration(&c.TotalRetryDuration, DefaultTotalRetryDuration) setDefaultBool(&c.EnableConcurrencyManagement, DefaultEnableConcurrencyManagement) diff --git a/httpclient/multipartrequest.go b/httpclient/multipartrequest.go index d58bb14..e5c9717 100644 --- a/httpclient/multipartrequest.go +++ b/httpclient/multipartrequest.go @@ -80,11 +80,9 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][] var ctx context.Context var cancel context.CancelFunc - c.Sugar.Debugf("TIMEOUT: %v", c.config.CustomTimeout) - - if c.config.CustomTimeout > 0 { - ctx, cancel = context.WithTimeout(context.Background(), c.config.CustomTimeout) - c.Sugar.Infow("Using timeout context for multipart request", zap.Duration("custom_timeout_seconds", c.config.CustomTimeout)) + if c.http.Timeout > 0 { + ctx, cancel = context.WithTimeout(context.Background(), c.http.Timeout) + c.Sugar.Infow("Using timeout context for multipart request", zap.Duration("custom_timeout_seconds", c.http.Timeout)) } else { ctx = context.Background() cancel = func() {}