Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk code is repeatedly calling curl_global_cleanup #2538

Closed
ButcherOfBlaviken opened this issue Jun 14, 2023 · 3 comments · Fixed by #2890
Closed

sdk code is repeatedly calling curl_global_cleanup #2538

ButcherOfBlaviken opened this issue Jun 14, 2023 · 3 comments · Fixed by #2890
Labels
bug This issue is a bug. p3 This is a minor priority issue pending-release This issue will be fixed by an approved PR that hasn't been released yet.

Comments

@ButcherOfBlaviken
Copy link

Describe the bug

source file: aws-sdk-cpp-1.10.20/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp

Sorry my English is not very good, I hope you can understand what I mean.

For every Aws::InitAPI and Aws::ShutdownAPI pair, aws sdk calls CurlHttpClient::InitGlobalState() and CurlHttpClient::CleanupGlobalState(). In the InitGlobalState function there is a bool type flag variable isInit, because of it InitGlobalState only calls libcurl initialization API curl_global_init once, but in CleanupGlobalState function, this flag won't be unset, so CleanupGlobalState is calling libcurl cleanup API curl_global_cleanup without any restriction, according to libcurl, This function releases resources acquired by curl_global_init and application should call curl_global_cleanup once for each call you make to curl_global_init.

For my case I use both aws S3 and libcurl based https, and aws sdk code cleanup the global initialization for my libcurl based code and caused CURLE_OUT_OF_MEMORY error when I try to make a https POST.

Expected Behavior

AWS sdk shall should call [curl_global_cleanup] once for each call it makes to [curl_global_init]

Current Behavior

AWS sdk calls [curl_global_cleanup] only once but calls [curl_global_init] multi-times

Reproduction Steps

always

Possible Solution

void CurlHttpClient::CleanupGlobalState()
{
if(true==isInit)
{
curl_global_cleanup();
isInit=false;
}
}

Additional Information/Context

https://curl.se/libcurl/c/curl_global_cleanup.html

AWS CPP SDK version used

aws-sdk-cpp-1.10.20

Compiler and Version used

aarch64-linux-gnu gcc version 9.4.0

Operating System and version

aarch64-linux-gnu

@ButcherOfBlaviken ButcherOfBlaviken added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 14, 2023
@SergeyRyabinin
Copy link
Contributor

Hi @ButcherOfBlaviken ,

SDK options struct has an option to disable calling this curl method, if you prefer to call it yourself:

/**
* libCurl infects everything with its global state. If it is being used then we automatically initialize and clean it up.
* If this is a problem for you, set this to false. If you manually initialize libcurl please add the option CURL_GLOBAL_ALL to your init call.
*/
bool initAndCleanupCurl;

At the same time, you are right with a proposed suggestion that we should check the flag value before attempting to curl_global_cleanup.
If you prefer, you could submit a PR with a change, otherwise we will follow up on it later.

Best regards,
Sergey

@yasminetalby yasminetalby added p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Jun 14, 2023
@jmklix
Copy link
Member

jmklix commented Mar 13, 2024

Testing your suggested changes

@jmklix jmklix linked a pull request Mar 13, 2024 that will close this issue
11 tasks
@jmklix jmklix added the pending-release This issue will be fixed by an approved PR that hasn't been released yet. label Mar 13, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p3 This is a minor priority issue pending-release This issue will be fixed by an approved PR that hasn't been released yet.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants