Skip to content

sdk code is repeatedly calling curl_global_cleanup #2538

Closed
@ButcherOfBlaviken

Description

@ButcherOfBlaviken

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

Activity

SergeyRyabinin

SergeyRyabinin commented on Jun 14, 2023

@SergeyRyabinin
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

added
p3This is a minor priority issue
and removed
needs-triageThis issue or PR still needs to be triaged.
on Jun 14, 2023
jmklix

jmklix commented on Mar 13, 2024

@jmklix
Member

Testing your suggested changes

linked a pull request that will close this issueonly call curl_global_cleanup once #2890on Mar 13, 2024
added
pending-releaseThis issue will be fixed by an approved PR that hasn't been released yet.
on Mar 13, 2024
github-actions

github-actions commented on Mar 14, 2024

@github-actions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.p3This is a minor priority issuepending-releaseThis issue will be fixed by an approved PR that hasn't been released yet.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @jmklix@SergeyRyabinin@ButcherOfBlaviken@yasminetalby

      Issue actions

        sdk code is repeatedly calling curl_global_cleanup · Issue #2538 · aws/aws-sdk-cpp