diff --git a/src/aws-cpp-sdk-core/source/http/HttpClientFactory.cpp b/src/aws-cpp-sdk-core/source/http/HttpClientFactory.cpp index 51453adf103..714e43d4109 100644 --- a/src/aws-cpp-sdk-core/source/http/HttpClientFactory.cpp +++ b/src/aws-cpp-sdk-core/source/http/HttpClientFactory.cpp @@ -4,6 +4,7 @@ */ #include +#include #if AWS_SDK_USE_CRT_HTTP #include @@ -181,6 +182,8 @@ namespace Aws { if(GetHttpClientFactory()) { + Aws::Internal::CleanupEC2MetadataClient(); + GetHttpClientFactory()->CleanupStaticState(); GetHttpClientFactory() = nullptr; } @@ -190,6 +193,8 @@ namespace Aws { CleanupHttp(); GetHttpClientFactory() = factory; + + Aws::Internal::InitEC2MetadataClient(); } std::shared_ptr CreateHttpClient(const Aws::Client::ClientConfiguration& clientConfiguration) diff --git a/src/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp b/src/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp index adf0378fde2..b721d5e78da 100644 --- a/src/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp +++ b/src/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp @@ -506,10 +506,15 @@ void CurlHttpClient::InitGlobalState() << ", ssl version: " << curlVersionData->ssl_version); isInit = true; #ifdef USE_AWS_MEMORY_MANAGEMENT - curl_global_init_mem(CURL_GLOBAL_ALL, &malloc_callback, &free_callback, &realloc_callback, &strdup_callback, &calloc_callback); + CURLcode curlResponseCode = curl_global_init_mem(CURL_GLOBAL_ALL, &malloc_callback, &free_callback, &realloc_callback, &strdup_callback, &calloc_callback); #else - curl_global_init(CURL_GLOBAL_ALL); + CURLcode curlResponseCode = curl_global_init(CURL_GLOBAL_ALL); #endif + if (curlResponseCode != CURLE_OK) + { + AWS_LOGSTREAM_FATAL(CURL_HTTP_CLIENT_TAG, "Failed to init curl, return code " << curlResponseCode); + isInit = false; + } } } @@ -517,6 +522,7 @@ void CurlHttpClient::InitGlobalState() void CurlHttpClient::CleanupGlobalState() { curl_global_cleanup(); + isInit = false; } Aws::String CurlInfoTypeToString(curl_infotype type) diff --git a/src/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp b/src/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp index 2af39e6098f..a559090e7a3 100644 --- a/src/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp +++ b/src/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp @@ -131,10 +131,20 @@ namespace Aws AmazonWebServiceResult AWSHttpResourceClient::GetResourceWithAWSWebServiceResult(const std::shared_ptr &httpRequest) const { AWS_LOGSTREAM_TRACE(m_logtag.c_str(), "Retrieving credentials from " << httpRequest->GetURIString()); + if (!m_httpClient) + { + AWS_LOGSTREAM_FATAL(m_logtag.c_str(), "Unable to get a response: missing http client!"); + return {{}, {}, HttpResponseCode::REQUEST_NOT_MADE}; + } for (long retries = 0;; retries++) { std::shared_ptr response(m_httpClient->MakeRequest(httpRequest)); + if (!response) + { + AWS_LOGSTREAM_FATAL(m_logtag.c_str(), "Unable to get a response: http client returned a nullptr!"); + return {{}, {}, HttpResponseCode::NO_RESPONSE}; + } if (response->GetResponseCode() == HttpResponseCode::OK) { diff --git a/tests/aws-cpp-sdk-eventbridge-tests/EventBridgeTests.cpp b/tests/aws-cpp-sdk-eventbridge-tests/EventBridgeTests.cpp index 3aee4e542ae..cd0892f4143 100644 --- a/tests/aws-cpp-sdk-eventbridge-tests/EventBridgeTests.cpp +++ b/tests/aws-cpp-sdk-eventbridge-tests/EventBridgeTests.cpp @@ -74,7 +74,7 @@ static std::shared_ptr buildEventBrid TEST_F(EventBridgeTests, TestPutEventsBasic) { - Aws::Client::ClientConfiguration clientConfig; + Aws::Client::ClientConfiguration clientConfig("default", true); clientConfig.region = "us-east-1"; Aws::Auth::AWSCredentials mockCreds("accessKey", "secretKey", "sessionToken"); @@ -100,7 +100,7 @@ TEST_F(EventBridgeTests, TestPutEventsBasic) TEST_F(EventBridgeTests, TestPutEventsMultiRegional) { - Aws::Client::ClientConfiguration clientConfig; + Aws::Client::ClientConfiguration clientConfig("default", true); clientConfig.region = "us-east-1"; Aws::Auth::AWSCredentials mockCreds("accessKey", "secretKey", "sessionToken"); @@ -168,7 +168,7 @@ TEST_F(EventBridgeTests, TestPutEventsEndpointTests) for(size_t tcIdx = 0; tcIdx < TEST_CASES.size(); ++tcIdx) { const EventBridgeEndpointTestCase& testCase = TEST_CASES[tcIdx]; - Aws::Client::ClientConfiguration clientConfig; + Aws::Client::ClientConfiguration clientConfig("default", true); clientConfig.region = testCase.clientRegion; clientConfig.useDualStack = testCase.useDualStackEndpoint; clientConfig.useFIPS = testCase.useFipsEndpoint;