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

s3-crt: Crash when calling PutObjectAsync without context #3171

Closed
1 task done
kledom opened this issue Nov 4, 2024 · 4 comments
Closed
1 task done

s3-crt: Crash when calling PutObjectAsync without context #3171

kledom opened this issue Nov 4, 2024 · 4 comments
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue

Comments

@kledom
Copy link

kledom commented Nov 4, 2024

Describe the bug

We are encountering a segmentation fault when calling the PutObjectAsync method in the s3-crt client. The issue specifically occurs when the Aws::Client::AsyncCallerContext parameter is not provided.

This issue did not occur with previous versions of the AWS SDK, suggesting a possible regression. Based on the timing, the problem may be linked to changes introduced in #3138.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The program should execute without crashing, even when PutObjectAsync is called without an AsyncCallerContext.

Current Behavior

The program crashes with a segmentation fault.

(gdb) 
#0  0x000055c273be98db in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_data (this=<optimized out>)
    at <redacted>/sysroots/skylake-server-64-vigem-linux/usr/include/c++/13.3.0/bits/basic_string.h:223
#1  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_is_local (this=<optimized out>)
    at <redacted>/sysroots/skylake-server-64-vigem-linux/usr/include/c++/13.3.0/bits/basic_string.h:264
#2  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::capacity (this=<optimized out>)
    at <redacted>/sysroots/skylake-server-64-vigem-linux/usr/include/c++/13.3.0/bits/basic_string.h:1171
#3  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign (this=0x28, __str="S3CrtClient")
    at <redacted>/sysroots/skylake-server-64-vigem-linux/usr/include/c++/13.3.0/bits/basic_string.tcc:283
#4  0x00007f80266c8acc in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign (__str=..., this=<optimized out>)
    at /usr/src/debug/aws-sdk-cpp/1.11.432/src/aws-cpp-sdk-core/include/aws/core/client/AsyncCallerContext.h:35
#5  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator= (__str=..., this=<optimized out>) at /usr/include/c++/13.3.0/bits/basic_string.h:814
#6  Aws::Client::MonitorContext::StartMonitorContext (this=0x28, client="S3CrtClient", request="PutObject", 
    httpRequest=std::shared_ptr<Aws::Http::HttpRequest> (use count 2, weak count 0) = {...})
    at /usr/src/debug/aws-sdk-cpp/1.11.432/src/aws-cpp-sdk-core/include/aws/core/client/AsyncCallerContext.h:35
#7  0x00007f802669a28c in Aws::S3Crt::S3CrtClient::PutObjectAsync(Aws::S3Crt::Model::PutObjectRequest const&, std::function<void (Aws::S3Crt::S3CrtClient const*, Aws::S3Crt::Model::PutObjectRequest const&, Aws::Utils::Outcome<Aws::S3Crt::Model::PutObjectResult, Aws::S3Crt::S3CrtError> const&, std::shared_ptr<Aws::Client::AsyncCallerContext const> const&)> const&, std::shared_ptr<Aws::Client::AsyncCallerContext const> const&) const (this=0x7f801011ea20, request=..., handler=..., 
    handlerContext=std::shared_ptr<const Aws::Client::AsyncCallerContext> (use count 2, weak count 0) = {...})
    at /usr/src/debug/aws-sdk-cpp/1.11.432/generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp:1107

Reproduction Steps

N/A

Possible Solution

No response

Additional Information/Context

No response

AWS CPP SDK version used

1.11.432

Compiler and Version used

(GCC) 13.3.0

Operating System and version

Linux / Yocto Scarthgap

@kledom kledom added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 4, 2024
@sbera87
Copy link
Contributor

sbera87 commented Nov 5, 2024

Could you please paste your code snippet so that we can troubleshoot your specific case?

@kledom
Copy link
Author

kledom commented Nov 6, 2024

You should be able to reproduce the issue with the following code snippet:

#include <aws/core/Aws.h>
#include <aws/s3-crt/S3CrtClient.h>
#include <aws/s3-crt/model/PutObjectRequest.h>
#include <aws/core/utils/ratelimiter/DefaultRateLimiter.h>
#include <aws/core/auth/AWSCredentialsProvider.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>
#include <aws/core/utils/Outcome.h>
#include <iostream>
#include <fstream>

void UploadFileAsync(const Aws::String& bucket_name, const Aws::String& object_name, const Aws::String& file_path) {
    Aws::S3Crt::S3CrtClient s3_client;

    Aws::S3Crt::Model::PutObjectRequest request;
    request.SetBucket(bucket_name);
    request.SetKey(object_name);

    auto file = Aws::MakeShared<Aws::FStream>("SampleAllocationTag", file_path.c_str(), std::ios_base::in | std::ios_base::binary);
    if (!file->good()) {
        std::cerr << "Failed to open file: " << file_path << std::endl;
        return;
    }

    request.SetBody(file);

    auto callback = [](const Aws::S3Crt::S3CrtClient* client,
                       const Aws::S3Crt::Model::PutObjectRequest& request,
                       const Aws::S3Crt::Model::PutObjectOutcome& outcome,
                       const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) {
        if (outcome.IsSuccess()) {
            std::cout << "File uploaded successfully!" << std::endl;
        } else {
            std::cerr << "Failed to upload file: " << outcome.GetError().GetMessage() << std::endl;
        }
    };

    // SEGFAULT:
    s3_client.PutObjectAsync(request, callback);
}

int main(int argc, char** argv) {
    if (argc != 4) {
        std::cerr << "Usage: " << argv[0] << " <bucket_name> <object_name> <file_path>" << std::endl;
        return 1;
    }

    Aws::SDKOptions options;
    Aws::InitAPI(options);
    {
        const Aws::String bucket_name(argv[1]);
        const Aws::String object_name(argv[2]);
        const Aws::String file_path(argv[3]);

        UploadFileAsync(bucket_name, object_name, file_path);

        std::this_thread::sleep_for(std::chrono::seconds(5));
    }
    Aws::ShutdownAPI(options);
    return 0;
}

A possible workaround is to pass a context to PutObjectAsync():

    std::shared_ptr<Aws::Client::AsyncCallerContext> context =
            Aws::MakeShared<Aws::Client::AsyncCallerContext>("PutObjectAllocationTag");
    context->SetUUID("SOME_UUUID");
    s3_client.PutObjectAsync(request, callback, context);

@sbera87 sbera87 self-assigned this Nov 6, 2024
@jmklix jmklix added p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Nov 6, 2024
@sbera87
Copy link
Contributor

sbera87 commented Nov 7, 2024

I could replicate the issue. A bug fix is under way and will be available soon.

@kledom kledom closed this as completed Nov 12, 2024
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

3 participants