-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add InitAPI call count to workaround multiple init mis-use #2710
Conversation
if(s_initCount != 1) | ||
{ | ||
if(!s_initCount) { | ||
AWS_LOGSTREAM_ERROR(ALLOCATION_TAG, "Unable to ShutdownAPI of AWS-SDK-CPP: the SDK was not initialized."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea how this one is going to be actually traced (without an initialized logger)
I don't want to add an assert here though.
void InitAPI(const SDKOptions &options) | ||
{ | ||
std::unique_lock<std::mutex> lock(s_initShutdownMutex); | ||
s_initCount += 1; | ||
if(s_initCount != 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we use an atomic int instead of a mutex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wanted to prevent simultaneous Init/Shutdown calls.
Issue #, if available:
This is a workaround for issues where customer is not able to control underlying libraries using the C++ SDK, such as #2699
Description of changes:
Add reference count on and blocking on mutex on InitAPI-ShutdownAPI methods.
This does not really fix the root architectural issue, but at least it provides a some level of workaround.
All consequent calls to InitAPI only increases the SDK usage count,
options
argument is completely ignored on any subsequent call, and only the last ShutdownAPI will actually shut down the library.Check all that applies:
Check which platforms you have built SDK on to verify the correctness of this PR.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.