Implement exponential backoff for 503

Amazon returns SlowDown when overloaded.  Also return ENOTSUP for 501
and immediately return EIO for 500 instead of retrying.  Fixes #603.
This commit is contained in:
Andrew Gaul 2019-02-01 19:46:06 -08:00
parent a442e843be
commit 8ff05d8e38

View File

@ -2065,7 +2065,7 @@ int S3fsCurl::RequestPerform(void)
}
// 1 attempt + retries...
for(int retrycnt = S3fsCurl::retries; 0 < retrycnt; retrycnt--){
for(int retrycnt = 0; retrycnt < S3fsCurl::retries; ++retrycnt){
// Requests
CURLcode curlCode = curl_easy_perform(hCurl);
@ -2081,11 +2081,6 @@ int S3fsCurl::RequestPerform(void)
S3FS_PRN_INFO3("HTTP response code %ld", LastResponseCode);
return 0;
}
if(500 <= LastResponseCode){
S3FS_PRN_ERR("HTTP response code = %ld Body Text: %s", LastResponseCode, (bodydata ? bodydata->str() : ""));
sleep(4);
break;
}
// Service response codes which are >= 300 && < 500
switch(LastResponseCode){
@ -2108,6 +2103,17 @@ int S3fsCurl::RequestPerform(void)
S3FS_PRN_DBG("Body Text: %s", (bodydata ? bodydata->str() : ""));
return -ENOENT;
case 501:
S3FS_PRN_INFO3("HTTP response code 501 was returned, returning ENOTSUP");
S3FS_PRN_DBG("Body Text: %s", (bodydata ? bodydata->str() : ""));
return -ENOTSUP;
case 503:
S3FS_PRN_INFO3("HTTP response code 503 was returned, slowing down");
S3FS_PRN_DBG("Body Text: %s", (bodydata ? bodydata->str() : ""));
sleep(4 << retry_count);
break;
default:
S3FS_PRN_ERR("HTTP response code %ld, returning EIO. Body Text: %s", LastResponseCode, (bodydata ? bodydata->str() : ""));
return -EIO;