aws / aws-sdk-cpp

AWS SDK for C++
Apache License 2.0
1.91k stars 1.04k forks source link

Segmentation fault occured in Aws::InitAPI when called by static object , previsously working for aws sdk version 1.8.186 #2961

Closed xuandong93 closed 1 month ago

xuandong93 commented 1 month ago

Describe the bug

Test constructor should successfully run but failed

Header


#ifndef testaws_HPP
#define testaws_HPP
#include <aws/core/Aws.h>

namespace Server
    {
        struct test
        {
            test();
        };

        static inline test t;

    } // namespace Server

//! Implementation
#include "server/impl/testaws.hpp"
#endif

IMPL

#ifndef testaws_HPP
#define testaws_HPP

#include "server/testaws.hpp"
inline Server::test::test()
    {
        Aws::SDKOptions options;
        Aws::InitAPI(options);
        Aws::ShutdownAPI(options);
        std::cout << " success\n";
    }
#endif

Main

#include "server/testaws.hpp"

int main ()
{
}

Expected Behavior

test constructor should successfully run but failed

Current Behavior

Segmentation fault at Aws::InitAPI()

Reproduction Steps

-

Possible Solution

-

Additional Information/Context

-

AWS CPP SDK version used

1.11.328

Compiler and Version used

gcc version 9.5.0

Operating System and version

ubuntu 22.04

sbiscigl commented 1 month ago

please consult the sdk usage dcumentation

The SDK for C++ and its dependencies use C++ static objects, and the order of static object destruction is not determined by the C++ standard. To avoid memory issues caused by the nondeterministic order of static variable destruction, do not wrap the calls to Aws::InitAPI and Aws::ShutdownAPI into another static object.

So yeah, you cant wrap the SDK in a static object because it causes a nondeterministic order of destruction.

xuandong93 commented 1 month ago

got it and thanks !

github-actions[bot] commented 1 month ago

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.