aws-sdk-cpp icon indicating copy to clipboard operation
aws-sdk-cpp copied to clipboard

Reference counting of `InitAPI`

Open jmklix opened this issue 2 years ago • 5 comments

Describe the feature

Provide a mechanism to prevent the sdk from breaking when InitAPI gets called when it has already been initialized.

Related issues/discussions:

  • https://github.com/aws/aws-sdk-cpp/discussions/2406
  • https://github.com/aws/aws-sdk-cpp/issues/456

Use Case

If code is being used in a library then there is currently no way for the library to know if InitAPI has already been called.

Proposed Solution

This will not/should not be RAII.

Using locks and reference counting this would allow multiple calls of InitAPI. Changes need to be make on this sdk and with the CRT

Other Information

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue, please leave a comment

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [X] This feature might incur a breaking change

jmklix avatar Mar 29 '23 17:03 jmklix

Just to clearify this for me: Calling InitAPI multiple times on a machine is okay as long as you don't do it inside the same application? Or has such a reference count to be system wide?

WolfgangVogl avatar Mar 30 '23 06:03 WolfgangVogl

Just to clearify this for me: Calling InitAPI multiple times on a machine is okay as long as you don't do it inside the same application? Or has such a reference count to be system wide?

Yes, that should be fine as long as the programs aren't sharing memory

jmklix avatar Mar 31 '23 23:03 jmklix

You can also handle the error result when it is already initialized, and ignore it.

jeking3 avatar Apr 24 '23 14:04 jeking3

https://github.com/aws/aws-sdk-cpp/commit/03036e49beca1b933b834c355459c8d182b00931

jmklix avatar Jun 30 '23 18:06 jmklix

Does anyone know why #2699 triggers only on MacOS? We see this only on MacOS, not Linux, and I'd like to understand what's Mac-specific here ...

johnkerl avatar Jun 07 '24 17:06 johnkerl

Does anyone know why https://github.com/aws/aws-sdk-cpp/issues/2699 triggers only on MacOS? We see this only on MacOS, not Linux, and I'd like to understand what's Mac-specific here ...

The issue linked is about the case when the Client outlives the InitAPI{}ShutdownAPI scope. This is a case of not following SDK basic-use documentation, however, I agree that the SDK API is not friendly, that's why, to prevent such kind of error, a client lifetime check has been added in https://github.com/aws/aws-sdk-cpp/pull/2515

The reason was failnig only on mac is due to the nature of undefined behavior, it may be different between different platforms and compilers.

Anyway, this issue is prevented from happening from different angles now.

SergeyRyabinin avatar Apr 09 '25 20:04 SergeyRyabinin

Count of InitAPI / ShutdownAPI calls has been added back in https://github.com/aws/aws-sdk-cpp/pull/2710 Thank you.

SergeyRyabinin avatar Apr 09 '25 20:04 SergeyRyabinin

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.

github-actions[bot] avatar Apr 09 '25 20:04 github-actions[bot]