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

Add InitAPI call count to workaround multiple init mis-use #2710

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

SergeyRyabinin
Copy link
Contributor

@SergeyRyabinin SergeyRyabinin commented Oct 11, 2023

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:

  • Did a review by yourself.
  • Added proper tests to cover this PR. (If tests are not applicable, explain.)
  • Checked if this PR is a breaking (APIs have been changed) change.
  • Checked if this PR will not introduce cross-platform inconsistent behavior.
  • Checked if this PR would require a ReadMe/Wiki update.

Check which platforms you have built SDK on to verify the correctness of this PR.

  • Linux
  • Windows
  • Android
  • MacOS
  • IOS
  • Other Platforms

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

if(s_initCount != 1)
{
if(!s_initCount) {
AWS_LOGSTREAM_ERROR(ALLOCATION_TAG, "Unable to ShutdownAPI of AWS-SDK-CPP: the SDK was not initialized.");
Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@SergeyRyabinin SergeyRyabinin marked this pull request as ready for review October 12, 2023 16:37
@SergeyRyabinin SergeyRyabinin merged commit 1f49f91 into main Oct 12, 2023
4 checks passed
@SergeyRyabinin SergeyRyabinin deleted the sr/apiRefCount branch October 12, 2023 16:38
@madsbk madsbk mentioned this pull request Aug 23, 2024
3 tasks
madsbk added a commit to madsbk/kvikio that referenced this pull request Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants