mirror of
https://github.com/jkl1337/duplicacy.git
synced 2026-01-02 19:54:54 -06:00
Merge pull request #298 from jay1337/master
Hubic retry mechanism improvement
This commit is contained in:
@@ -72,7 +72,7 @@ func NewHubicClient(tokenFile string) (*HubicClient, error) {
|
|||||||
KeepAlive: 30 * time.Second,
|
KeepAlive: 30 * time.Second,
|
||||||
}).Dial,
|
}).Dial,
|
||||||
TLSHandshakeTimeout: 60 * time.Second,
|
TLSHandshakeTimeout: 60 * time.Second,
|
||||||
ResponseHeaderTimeout: 30 * time.Second,
|
ResponseHeaderTimeout: 300 * time.Second,
|
||||||
ExpectContinueTimeout: 10 * time.Second,
|
ExpectContinueTimeout: 10 * time.Second,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -100,7 +100,7 @@ func (client *HubicClient) call(url string, method string, input interface{}, ex
|
|||||||
var response *http.Response
|
var response *http.Response
|
||||||
|
|
||||||
backoff := 1
|
backoff := 1
|
||||||
for i := 0; i < 8; i++ {
|
for i := 0; i < 11; i++ {
|
||||||
|
|
||||||
LOG_DEBUG("HUBIC_CALL", "%s %s", method, url)
|
LOG_DEBUG("HUBIC_CALL", "%s %s", method, url)
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ func (client *HubicClient) call(url string, method string, input interface{}, ex
|
|||||||
response, err = client.HTTPClient.Do(request)
|
response, err = client.HTTPClient.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if url != HubicCredentialURL {
|
if url != HubicCredentialURL {
|
||||||
retryAfter := time.Duration(rand.Float32() * 1000.0 * float32(backoff))
|
retryAfter := time.Duration((0.5 + rand.Float32()) * 1000.0 * float32(backoff))
|
||||||
LOG_INFO("HUBIC_CALL", "%s %s returned an error: %v; retry after %d milliseconds", method, url, err, retryAfter)
|
LOG_INFO("HUBIC_CALL", "%s %s returned an error: %v; retry after %d milliseconds", method, url, err, retryAfter)
|
||||||
time.Sleep(retryAfter * time.Millisecond)
|
time.Sleep(retryAfter * time.Millisecond)
|
||||||
backoff *= 2
|
backoff *= 2
|
||||||
@@ -197,7 +197,13 @@ func (client *HubicClient) call(url string, method string, input interface{}, ex
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
} else if response.StatusCode >= 500 && response.StatusCode < 600 {
|
} else if response.StatusCode >= 500 && response.StatusCode < 600 {
|
||||||
retryAfter := time.Duration(rand.Float32() * 1000.0 * float32(backoff))
|
retryAfter := time.Duration((0.5 + rand.Float32()) * 1000.0 * float32(backoff))
|
||||||
|
LOG_INFO("HUBIC_RETRY", "Response status: %d; retry after %d milliseconds", response.StatusCode, retryAfter)
|
||||||
|
time.Sleep(retryAfter * time.Millisecond)
|
||||||
|
backoff *= 2
|
||||||
|
continue
|
||||||
|
} else if response.StatusCode == 408 {
|
||||||
|
retryAfter := time.Duration((0.5 + rand.Float32()) * 1000.0 * float32(backoff))
|
||||||
LOG_INFO("HUBIC_RETRY", "Response status: %d; retry after %d milliseconds", response.StatusCode, retryAfter)
|
LOG_INFO("HUBIC_RETRY", "Response status: %d; retry after %d milliseconds", response.StatusCode, retryAfter)
|
||||||
time.Sleep(retryAfter * time.Millisecond)
|
time.Sleep(retryAfter * time.Millisecond)
|
||||||
backoff *= 2
|
backoff *= 2
|
||||||
|
|||||||
Reference in New Issue
Block a user