requester: purge max request jobs (#1379)

* requester: purge max request jobs

* request: rm unused error

---------

Co-authored-by: shazbert <ryan.oharareid@thrasher.io>
This commit is contained in:
Ryan O'Hara-Reid
2024-01-22 12:48:45 +11:00
committed by GitHub
parent d8ec20576d
commit 0c40f90ceb
15 changed files with 5 additions and 54 deletions

View File

@@ -9,7 +9,6 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"sync/atomic"
"time"
"github.com/thrasher-corp/gocryptotrader/common"
@@ -40,7 +39,6 @@ var (
// ErrAuthRequestFailed is a wrapping error to denote that it's an auth request that failed
ErrAuthRequestFailed = errors.New("authenticated request failed")
errMaxRequestJobs = errors.New("max request jobs reached")
errRequestFunctionIsNil = errors.New("request function is nil")
errRequestItemNil = errors.New("request item is nil")
errInvalidPath = errors.New("invalid path")
@@ -93,13 +91,7 @@ func (r *Requester) SendPayload(ctx context.Context, ep EndpointLimit, newReques
return errRequestFunctionIsNil
}
if atomic.LoadInt32(&r.jobs) >= MaxRequestJobs {
return errMaxRequestJobs
}
atomic.AddInt32(&r.jobs, 1)
err := r.doRequest(ctx, ep, newRequest)
atomic.AddInt32(&r.jobs, -1)
if err != nil && requestType == AuthenticatedRequest {
err = common.AppendError(err, ErrAuthRequestFailed)
}

View File

@@ -301,17 +301,6 @@ func TestDoRequest(t *testing.T) {
t.Fatalf("received: %v but expected: %v", err, newError)
}
// max request job ceiling
r.jobs = MaxRequestJobs
err = r.SendPayload(ctx, UnAuth, func() (*Item, error) {
return &Item{Path: testURL}, nil
}, UnauthenticatedRequest)
if !errors.Is(err, errMaxRequestJobs) {
t.Fatalf("received: %v but expected: %v", err, errMaxRequestJobs)
}
// reset jobs
r.jobs = 0
r._HTTPClient, err = newProtectedClient(common.NewHTTPClientWithTimeout(0))
if err != nil {
t.Fatal(err)

View File

@@ -11,17 +11,15 @@ import (
// Const vars for rate limiter
const (
DefaultMaxRequestJobs int32 = 50
DefaultMaxRetryAttempts = 3
DefaultMutexLockTimeout = 50 * time.Millisecond
drainBodyLimit = 100000
proxyTLSTimeout = 15 * time.Second
userAgent = "User-Agent"
DefaultMaxRetryAttempts = 3
DefaultMutexLockTimeout = 50 * time.Millisecond
drainBodyLimit = 100000
proxyTLSTimeout = 15 * time.Second
userAgent = "User-Agent"
)
// Vars for rate limiter
var (
MaxRequestJobs = DefaultMaxRequestJobs
MaxRetryAttempts = DefaultMaxRetryAttempts
globalReporter Reporter
)
@@ -34,7 +32,6 @@ type Requester struct {
name string
userAgent string
maxRetries int
jobs int32
Nonce nonce.Nonce
disableRateLimiter int32
backoff Backoff