CurlHandleContainer/StlAllocator crash on shutdown #1833
Labels
bug
This issue is a bug.
pending-release
This issue will be fixed by an approved PR that hasn't been released yet.
Confirm by changing [ ] to [x] below to ensure that it's a bug:
Describe the bug
This problem happens on shutdown of the API:
It is a race condition, please see below for reproducability.
SDK version number
1.9.92 - the affected code is still present in today's
master
(1.9.165).Platform/OS/Hardware/Device
Linux/ubuntu 18.04.
To Reproduce (observed behavior)
I was able to reproduce this problem reliably in a unit tests, but any other exit sequence involving the steps below should trigger the same outcome.
Here is the
gdb
trace with some more details:Analysis
I printed extra context out when the application crashed, which shows the sequence of events:
CleanupCrt()
is called on API shutdown.This calls
Aws::Delete(g_apiHandle)
ApiHandle::~ApiHandle()
setsg_allocator = nullptr
(important for the events below).AWSClient::~AWSClient()
is called (that is where the above backtrace starts).CurlHttpClient::~CurlHttpClient
is called next (please refer to above strack trace for the remaining events).Aws::Http::CurlHandleContainer::~CurlHandleContainer()
is called when them_curlHandleContainer
of theCurlHttpClient
is destructed.The destructor in (6) calls the
ShutdownAndWait
operation:Aws::Utils::ExclusiveOwnershipResourceManager<CURL*> m_handleContainer
is invoking the following code:RESOURCE_TYPE
in this case (as per code and stack trace) is aCURL*
(akavoid*
) with anAws::Crt::StlAllocator<void*>
allocator.resources
in the above is constructed, theStlAllocator
default constructor is called:g_allocator
is at this timeNULL
(after the call in (3) above).resources = m_resources;
invokes thestd::vector::operator =
resources
,g_allocator
isNULL
.assert
when callingaws_mem_acquire
Possible fix
Since
m_resources
is empty whenShutdownAndWait
is called, we can usestd::move
to constructresources
in place:This works since, at the time of calling,
m_resources
still has a reference to its allocator. When themove
is performed, the allocator ofm_resources
is used, avoiding the problem with the default-constructed (NULL) allocator ofresources
.The text was updated successfully, but these errors were encountered: