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

Aws::ShutdownAPI hangs when S3Crt is used #2769

Closed
jeanbez opened this issue Nov 28, 2023 · 3 comments
Closed

Aws::ShutdownAPI hangs when S3Crt is used #2769

jeanbez opened this issue Nov 28, 2023 · 3 comments
Labels
response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.

Comments

@jeanbez
Copy link

jeanbez commented Nov 28, 2023

Describe the bug

When calling the Aws::ShutdownAPI(options) the execution seems to hang, this happens in MacOS with the latest version of the SDK and only when using the S3Crt.

Expected Behavior

Shutdown to complete and application to exit successfully.

Current Behavior

The logs indicate it get stuck mid-shutdown process:

[INFO] 2023-11-28 23:13:05.921 Aws_Init_Cleanup [0x7ff8517cae80] Shutdown AWS SDK for C++.
[DEBUG] 2023-11-28 23:13:05.922 HttpClientFactory [0x7ff8517cae80] Cleanup Http Static State
[DEBUG] 2023-11-28 23:13:05.922 HttpClientFactory [0x7ff8517cae80] Cleanup Curl Http Client

Reproduction Steps

Sample code based on the provided examples in documentation that cause this behavior:

#include <iostream>
#include <aws/core/Aws.h>
#include <aws/s3-crt/S3CrtClient.h>
#include <aws/s3-crt/model/CreateBucketRequest.h>
#include <aws/s3-crt/model/BucketLocationConstraint.h>
#include <aws/s3-crt/model/DeleteBucketRequest.h>
#include <aws/s3-crt/model/PutObjectRequest.h>
#include <aws/s3-crt/model/GetObjectRequest.h>
#include <aws/s3-crt/model/DeleteObjectRequest.h>
#include <aws/s3-crt/model/HeadObjectRequest.h>

int main() {
    std::shared_ptr<Aws::S3Crt::S3CrtClient> aws_crt_client;

    Aws::SDKOptions options;
    options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;

    Aws::InitAPI(options);

    const double throughput_target_gbps = 100;
    const uint64_t part_size = 1 * 1024 * 1024; // 1 MB

    Aws::S3Crt::ClientConfiguration ctr_config;
    ctr_config.region = Aws::Region::US_WEST_1;
    ctr_config.throughputTargetGbps = throughput_target_gbps;
    ctr_config.partSize = part_size;

    aws_crt_client = std::make_shared<Aws::S3Crt::S3CrtClient>(ctr_config);

    Aws::S3Crt::Model::ListBucketsOutcome outcome = aws_crt_client->ListBuckets();

    if (outcome.IsSuccess()) {
        std::cout << "All buckets under my account:" << std::endl;

        for (auto const& bucket : outcome.GetResult().GetBuckets())
        {
            std::cout << "  * " << bucket.GetName() << std::endl;
        }
        std::cout << std::endl;
    }
    else {
        std::cout << "ListBuckets error:\n"<< outcome.GetError() << std::endl << std::endl;
    }

    Aws::ShutdownAPI(options);

    return 0;
}

The contents are listed, and upon calling shutdown, the code hangs indefinitely. Upon interrupting the execution in lldb the stack trace is the following:

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x00007ff80e1b55d6 libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0x00007ff80e1f276b libsystem_pthread.dylib`_pthread_cond_wait + 1211
    frame #2: 0x00007ff80e12a3c2 libc++.1.dylib`std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 18
    frame #3: 0x00007ff80e12ac37 libc++.1.dylib`std::__1::__assoc_sub_state::__sub_wait(std::__1::unique_lock<std::__1::mutex>&) + 45
    frame #4: 0x00007ff80e12ac9e libc++.1.dylib`std::__1::__assoc_sub_state::wait() + 46
    frame #5: 0x0000000101216d85 libaws-crt-cpp.dylib`Aws::Crt::Io::ClientBootstrap::~ClientBootstrap() + 45
    frame #6: 0x0000000100845b70 libaws-cpp-sdk-core.dylib`std::__1::shared_ptr<Aws::Crt::Io::ClientBootstrap>::operator=[abi:v160006](std::__1::shared_ptr<Aws::Crt::Io::ClientBootstrap> const&) + 66
    frame #7: 0x0000000100845c5d libaws-cpp-sdk-core.dylib`Aws::CleanupCrt() + 34
    frame #8: 0x0000000100845787 libaws-cpp-sdk-core.dylib`Aws::ShutdownAPI(Aws::SDKOptions const&) + 544

Possible Solution

No response

Additional Information/Context

No response

AWS CPP SDK version used

1.11.211

Compiler and Version used

Apple clang version 15.0.0 (clang-1500.0.40.1)

Operating System and version

MacOs Sonoma 14.0 (23A344)

@jeanbez jeanbez added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 28, 2023
@sbiscigl
Copy link
Contributor

sbiscigl commented Nov 29, 2023

Hey @jeanbez thanks for reaching out i'd like to redirect you to our basic usage documentation specifically

Aws::InitAPI(options);
{
    // make your SDK calls here.
}
Aws::ShutdownAPI(options);

because the specific issue is that your shared ptr for the s3 client still exists when you call shutdown. because of this shutdown will wait for you to delete the client to release the associated resources. refactoring your code to use the RAII to automatically clean up the client like

#include <iostream>
#include <aws/core/Aws.h>
#include <aws/s3-crt/S3CrtClient.h>
#include <aws/s3-crt/model/CreateBucketRequest.h>

int main() {

  Aws::SDKOptions options;
  options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;

  Aws::InitAPI(options);
  {
    std::shared_ptr<Aws::S3Crt::S3CrtClient> aws_crt_client;
    const double throughput_target_gbps = 100;
    const uint64_t part_size = 1 * 1024 * 1024; // 1 MB

    Aws::S3Crt::ClientConfiguration ctr_config;
    ctr_config.region = Aws::Region::US_WEST_1;
    ctr_config.throughputTargetGbps = throughput_target_gbps;
    ctr_config.partSize = part_size;

    aws_crt_client = std::make_shared<Aws::S3Crt::S3CrtClient>(ctr_config);

    Aws::S3Crt::Model::ListBucketsOutcome outcome = aws_crt_client->ListBuckets();

    if (outcome.IsSuccess()) {
      std::cout << "All buckets under my account:" << std::endl;

      for (auto const&bucket: outcome.GetResult().GetBuckets()) {
        std::cout << "  * " << bucket.GetName() << std::endl;
      }
      std::cout << std::endl;
    }
    else {
      std::cout << "ListBuckets error:\n" << outcome.GetError() << std::endl << std::endl;
    }
  }
  Aws::ShutdownAPI(options);
  return 0;
}

will make sure that std::shared_ptr<Aws::S3Crt::S3CrtClient> aws_crt_client has been destructed when shutdown is called. this could also be accomplished by adding aws_crt_client.reset(); before calling shutdown but i'd recommend using RAII instead of directly invoking reset.

let me know if you have any questions.

@sbiscigl sbiscigl added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 29, 2023
@jeanbez
Copy link
Author

jeanbez commented Nov 29, 2023

got it, thanks! calling reset solved the issue

@jeanbez jeanbez closed this as completed Nov 29, 2023
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.
Projects
None yet
Development

No branches or pull requests

2 participants