From 8ff05d8e38b24ccc2d7555e7578d361cdf2abded Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Fri, 1 Feb 2019 19:46:06 -0800 Subject: [PATCH] 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. --- src/curl.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/curl.cpp b/src/curl.cpp index c7a4788..9976290 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -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;