Skip to content

LexRuntimeService segmentation fault #684

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

Closed
kowalikm opened this issue Oct 3, 2017 · 2 comments
Closed

LexRuntimeService segmentation fault #684

kowalikm opened this issue Oct 3, 2017 · 2 comments
Labels
closed-for-staleness help wanted We are asking the community to submit a PR to resolve this issue.

Comments

@kowalikm
Copy link

kowalikm commented Oct 3, 2017

Hello,
I'm using gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4). Trying to build Application using Kitt.ai Snowboy Hotword Detection and AWS Lex.

When I build demo lex application - everything seems to be ok (it returns valid intent):

int main(int argc, char *argv[]) {

	if(argc != 2) {
		std::cerr << "Wrong args!" << std::endl;
		return -1;
	}
	Aws::SDKOptions options;
	Aws::InitAPI(options);

	Aws::LexRuntimeService::LexRuntimeServiceClient client;
	Aws::LexRuntimeService::Model::PostContentRequest request;
	request.SetBotName("SmartCook");
	request.SetBotAlias("$LATEST");
	request.SetUserId("***");
	request.SetContentType("audio/l16; rate=16000; channels=1");
	auto body = Aws::MakeShared<Aws::FStream>("command.tmp", "command.tmp", std::ios::in | std::ios::binary);


	if(!body) {
		std::cerr << std::string("Cannot open file ") + std::string(argv[1])  + std::string("!") << std::endl;
		return -2;
	} else {
		body->seekg(0, std::ios::end);
		unsigned long size = body->tellg();
		body->seekg(0);
		std::cout << "Body length: " << size << std::endl;
	}

	request.SetBody(body);

	auto outcome = client.PostContent(request);
	Aws::LexRuntimeService::Model::PostContentResult& result = outcome.GetResult();
	auto error = outcome.GetError();

	std::cout << "PostContent done: " << outcome.IsSuccess() << std::endl;
	std::cerr << "Error: " << error.GetMessage() << std::endl;
	std::cout << "Intent: " << result.GetIntentName() << std::endl;
	std::cout << "Slots: " << result.GetSlots() << std::endl;
	Aws::ShutdownAPI(options);

	return 0;
}

But when I use same code with my other application I get following SIGSEGV:

Thread #1 [SmartVoice] 11001 [core: 1] (Suspended : Signal : SIGSEGV:Segmentation fault)
__gnu_cxx::__exchange_and_add() at atomicity.h:49 0x409e4e
__gnu_cxx::__exchange_and_add_dispatch() at atomicity.h:82 0x409ee5
std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release at shared_ptr_base.h:147 0x40bc8d
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count at shared_ptr_base.h:659 0x40b435
std::__shared_ptr<Aws::Utils::RateLimits::RateLimiterInterface, (__gnu_cxx::_Lock_policy)2>::
__shared_ptr at shared_ptr_base.h:925 0x40a9c0
std::shared_ptrAws::Utils::RateLimits::RateLimiterInterface::~shared_ptr() at shared_ptr.h:93 0x40a9dc
Aws::Client::ClientConfiguration::~ClientConfiguration() at ClientConfiguration.h:48 0x40a9fe
Aws::Internal::AWSHttpResourceClient::AWSHttpResourceClient() at 0x7ffff7371872
Aws::Internal::EC2MetadataClient::EC2MetadataClient() at 0x7ffff7371ee3
void __gnu_cxx::new_allocatorAws::Internal::EC2MetadataClient::constructAws::Internal::EC2MetadataClient() at 0x7ffff737bfb5
std::enable_if<std::_and<std::allocator_traits<Aws::AllocatorAws::Internal::EC2MetadataClient >::__construct_helperAws::Internal::EC2MetadataClient::type>::value, void>::type std::allocator_traits<Aws::AllocatorAws::Internal::EC2MetadataClient >::_S_constructAws::Internal::EC2MetadataClient() at 0x7ffff737bd67
decltype (_S_construct({parm#1}, {parm#2})) std::allocator_traits<Aws::AllocatorAws::Internal::EC2MetadataClient >::constructAws::Internal::EC2MetadataClient at 0x7ffff737bb2b
std::_Sp_counted_ptr_inplace<Aws::Internal::EC2MetadataClient, Aws::AllocatorAws::Internal::EC2MetadataClient, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<> at 0x7ffff737b7c3
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<Aws::Internal::EC2MetadataClient, Aws::AllocatorAws::Internal::EC2MetadataClient> at 0x7ffff737b25c
std::__shared_ptr<Aws::Internal::EC2MetadataClient, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<Aws::AllocatorAws::Internal::EC2MetadataClient> at 0x7ffff737aea8
std::shared_ptrAws::Internal::EC2MetadataClient::shared_ptr<Aws::AllocatorAws::Internal::EC2MetadataClient>() at 0x7ffff737a826
std::shared_ptrAws::Internal::EC2MetadataClient std::allocate_shared<Aws::Internal::EC2MetadataClient, Aws::AllocatorAws::Internal::EC2MetadataClient>() at 0x7ffff7379bfe
std::shared_ptrAws::Internal::EC2MetadataClient Aws::MakeSharedAws::Internal::EC2MetadataClient() at 0x7ffff7379050
Aws::Config::EC2InstanceProfileConfigLoader::EC2InstanceProfileConfigLoader() at 0x7ffff7376e1c
void __gnu_cxx::new_allocatorAws::Config::EC2InstanceProfileConfigLoader::constructAws::Config::EC2InstanceProfileConfigLoader() at 0x7ffff73547b6
std::enable_if<std::_and<std::allocator_traits<Aws::AllocatorAws::Config::EC2InstanceProfileConfigLoader >::__construct_helperAws::Config::EC2InstanceProfileConfigLoader::type>::value, void>::type std::allocator_traits<Aws::AllocatorAws::Config::EC2InstanceProfileConfigLoader >::_S_constructAws::Config::EC2InstanceProfileConfigLoader() at 0x7ffff73544e5
decltype (_S_construct({parm#1}, {parm#2})) std::allocator_traits<Aws::AllocatorAws::Config::EC2InstanceProfileConfigLoader >::constructAws::Config::EC2InstanceProfileConfigLoader at 0x7ffff7354107
std::_Sp_counted_ptr_inplace<Aws::Config::EC2InstanceProfileConfigLoader, Aws::AllocatorAws::Config::EC2InstanceProfileConfigLoader, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<> at 0x7ffff7353b27
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<Aws::Config::EC2InstanceProfileConfigLoader, Aws::AllocatorAws::Config::EC2InstanceProfileConfigLoader> at 0x7ffff73534d4
std::__shared_ptr<Aws::Config::EC2InstanceProfileConfigLoader, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<Aws::AllocatorAws::Config::EC2InstanceProfileConfigLoader> at 0x7ffff7353088
std::shared_ptrAws::Config::EC2InstanceProfileConfigLoader::shared_ptr<Aws::AllocatorAws::Config::EC2InstanceProfileConfigLoader>() at 0x7ffff7352d76
std::shared_ptrAws::Config::EC2InstanceProfileConfigLoader std::allocate_shared<Aws::Config::EC2InstanceProfileConfigLoader, Aws::AllocatorAws::Config::EC2InstanceProfileConfigLoader>() at 0x7ffff7352738
std::shared_ptrAws::Config::EC2InstanceProfileConfigLoader Aws::MakeSharedAws::Config::EC2InstanceProfileConfigLoader() at 0x7ffff7351ffe
Aws::Auth::InstanceProfileCredentialsProvider::InstanceProfileCredentialsProvider() at 0x7ffff7350713
void __gnu_cxx::new_allocatorAws::Auth::InstanceProfileCredentialsProvider::constructAws::Auth::InstanceProfileCredentialsProvider() at 0x7ffff7361c4c
std::enable_if<std::_and<std::allocator_traits<Aws::AllocatorAws::Auth::InstanceProfileCredentialsProvider >::__construct_helperAws::Auth::InstanceProfileCredentialsProvider::type>::value, void>::type std::allocator_traits<Aws::AllocatorAws::Auth::InstanceProfileCredentialsProvider >::_S_constructAws::Auth::InstanceProfileCredentialsProvider() at 0x7ffff7361a7d
decltype (_S_construct({parm#1}, {parm#2})) std::allocator_traits<Aws::AllocatorAws::Auth::InstanceProfileCredentialsProvider >::constructAws::Auth::InstanceProfileCredentialsProvider at 0x7ffff7361687
std::_Sp_counted_ptr_inplace<Aws::Auth::InstanceProfileCredentialsProvider, Aws::AllocatorAws::Auth::InstanceProfileCredentialsProvider, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<> at 0x7ffff7360f7d
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<Aws::Auth::InstanceProfileCredentialsProvider, Aws::AllocatorAws::Auth::InstanceProfileCredentialsProvider> at 0x7ffff736068e
std::__shared_ptr<Aws::Auth::InstanceProfileCredentialsProvider, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<Aws::AllocatorAws::Auth::InstanceProfileCredentialsProvider> at 0x7ffff73600b0
std::shared_ptrAws::Auth::InstanceProfileCredentialsProvider::shared_ptr<Aws::AllocatorAws::Auth::InstanceProfileCredentialsProvider>() at 0x7ffff735fc4a
std::shared_ptrAws::Auth::InstanceProfileCredentialsProvider std::allocate_shared<Aws::Auth::InstanceProfileCredentialsProvider, Aws::AllocatorAws::Auth::InstanceProfileCredentialsProvider>() at 0x7ffff735f78e
std::shared_ptrAws::Auth::InstanceProfileCredentialsProvider Aws::MakeSharedAws::Auth::InstanceProfileCredentialsProvider() at 0x7ffff735f14d
Aws::Auth::DefaultAWSCredentialsProviderChain::DefaultAWSCredentialsProviderChain() at 0x7ffff735ea9f
void __gnu_cxx::new_allocatorAws::Auth::DefaultAWSCredentialsProviderChain::constructAws::Auth::DefaultAWSCredentialsProviderChain() at 0x7ffff6ecd446
std::enable_if<std::_and<std::allocator_traits<Aws::AllocatorAws::Auth::DefaultAWSCredentialsProviderChain >::__construct_helperAws::Auth::DefaultAWSCredentialsProviderChain::type>::value, void>::type std::allocator_traits<Aws::AllocatorAws::Auth::DefaultAWSCredentialsProviderChain >::_S_constructAws::Auth::DefaultAWSCredentialsProviderChain() at 0x7ffff6ecce09
decltype (_S_construct({parm#1}, {parm#2})) std::allocator_traits<Aws::AllocatorAws::Auth::DefaultAWSCredentialsProviderChain >::constructAws::Auth::DefaultAWSCredentialsProviderChain at 0x7ffff6ecc423
std::_Sp_counted_ptr_inplace<Aws::Auth::DefaultAWSCredentialsProviderChain, Aws::AllocatorAws::Auth::DefaultAWSCredentialsProviderChain, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<> at 0x7ffff6ecb687
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<Aws::Auth::DefaultAWSCredentialsProviderChain, Aws::AllocatorAws::Auth::DefaultAWSCredentialsProviderChain> at 0x7ffff6eca9e2
std::__shared_ptr<Aws::Auth::DefaultAWSCredentialsProviderChain, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<Aws::AllocatorAws::Auth::DefaultAWSCredentialsProviderChain> at 0x7ffff6ec9bae
std::shared_ptrAws::Auth::DefaultAWSCredentialsProviderChain::shared_ptr<Aws::AllocatorAws::Auth::DefaultAWSCredentialsProviderChain>() at 0x7ffff6ec8cf2
std::shared_ptrAws::Auth::DefaultAWSCredentialsProviderChain std::allocate_shared<Aws::Auth::DefaultAWSCredentialsProviderChain, Aws::AllocatorAws::Auth::DefaultAWSCredentialsProviderChain>() at 0x7ffff6ec7118
std::shared_ptrAws::Auth::DefaultAWSCredentialsProviderChain Aws::MakeSharedAws::Auth::DefaultAWSCredentialsProviderChain() at 0x7ffff6ec50d9
Aws::LexRuntimeService::LexRuntimeServiceClient::LexRuntimeServiceClient() at 0x7ffff6ebb555
SmartVoice::AwsLexWrapper::recognize() at AwsLexWrapper.cpp:32 0x40a07a
SmartVoice::CommandDetector::commandSilenceDetected() at CommandDetector.cpp:115 0x40eea9
SmartVoice::CommandDetector::startDetection() at CommandDetector.cpp:57 0x40eaa6
main() at main.cpp:26 0x413602

@wps132230 wps132230 added bug This issue is a bug. help wanted labels Oct 5, 2017
@kowalikm
Copy link
Author

kowalikm commented Oct 10, 2017

Hello, I tried to build application again with QtFramework. Here is code:

lexwrapper.h

#ifndef LEXWRAPPER_H
#define LEXWRAPPER_H

#include <QObject>
#include <aws/core/Aws.h>

class LexWrapper : public QObject
{
    Q_OBJECT
public:
    explicit LexWrapper(QObject *parent = nullptr);

    ~LexWrapper();

signals:

public slots:
    void recognizeCommand(const QString& path);

private:
    Aws::SDKOptions m_options;
};

#endif // LEXWRAPPER_H

lexwrapper.cpp

#include "lexwrapper.h"

#include <aws/lex/LexRuntimeServiceClient.h>
#include <aws/lex/model/PostContentRequest.h>
#include <aws/core/utils/Outcome.h>
#include <fstream>

#include <QDebug>

LexWrapper::LexWrapper(QObject *parent)
    : QObject(parent)
{
    Aws::InitAPI(m_options);
}

LexWrapper::~LexWrapper()
{
    Aws::ShutdownAPI(m_options);
}

void LexWrapper::recognizeCommand(const QString &path)
{
    using namespace Aws::LexRuntimeService;

    QScopedPointer<Model::PostContentRequest> request(new Model::PostContentRequest);
    request->SetBotName("SmartCook");
    request->SetBotAlias("$LATEST");
    request->SetUserId("***");
    request->SetContentType("audio/l16; rate=16000; channels=1");

    auto body = Aws::MakeShared<Aws::FStream>("voice.tmp", path.toStdString(), std::ios::in | std::ios::binary);

    if(!body) {
        qCritical() << "Cannot open file stream: " << path;
        return ;
    }

    request->SetBody(body);

    QScopedPointer<LexRuntimeServiceClient> client(new LexRuntimeServiceClient);

    auto outcome = client->PostContent(*request);

    if(outcome.IsSuccess()) {
        Model::PostContentResult& result = outcome.GetResult();

        qDebug() << "PostContent success: Intent[" << result.GetIntentName().c_str()
                 << "] Slots[" << result.GetSlots().c_str() << "]";
    } else {
        auto error = outcome.GetError();

        qDebug() << "PostContent failed: Error[" << error.GetMessage().c_str() << "]";
    }
}

Here is usage of LexWrapper in my application:

void VoiceCommandDetector::commandSilenceDetected()
{
    if(m_isCommandSpeakingStarted) {
        qDebug() << "Speaking ended, no command recognized.";

        QFile tempFile("voice.tmp");
        tempFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
        tempFile.write(m_commandCache);
        tempFile.close();

        qDebug() << "Using Lex for NLU recognition...";

        QScopedPointer<LexWrapper> lexWrapper(new LexWrapper);
        lexWrapper->recognizeCommand(tempFile.fileName());

        qDebug() << "After lex recognition.";

        resetCommandRecognition();
    }
}

Used libs:
-lsnowboy-detect -lcblas -latlas -laws-cpp-sdk-core -laws-cpp-sdk-lex

Tried on g++-4.8 and g++-5.4.0 (with _GLIBCXX_USE_CXX11_ABI=0)

Crashed in bits/basic_string.h:3121:

      // Capacity:
      ///  Returns the number of characters in the string, not including any
      ///  null-termination.
      size_type
      size() const _GLIBCXX_NOEXCEPT
      { return _M_rep()->_M_length; }  // <- HERE

Stack:

1 std::basic_string<char, std::char_traits, Aws::Allocator>::size basic_string.h 3121 0x40db52
2 std::basic_string<char, std::char_traits, Aws::Allocator>::assign basic_string.tcc 706 0x40d2c3
3 std::basic_string<char, std::char_traits, Aws::Allocator>::assign basic_string.h 3547 0x40cba2
4 Aws::LexRuntimeService::Model::PostContentRequest::SetBotName PostContentRequest.h 66 0x40c34b
5 LexWrapper::recognizeCommand lexwrapper.cpp 26 0x40b624
6 VoiceCommandDetector::commandSilenceDetected voicecommanddetector.cpp 80 0x40ab9d
7 VoiceCommandDetector::reciveData voicecommanddetector.cpp 36 0x40a7cb
8 QtPrivate::FunctorCall<QtPrivate::IndexesList<0>, QtPrivate::List<QByteArray const&>, void, void (VoiceCommandDetector:: *)(QByteArray const&)>::call qobjectdefs_impl.h 136 0x40918a
9 QtPrivate::FunctionPointer<void (VoiceCommandDetector:: *)(QByteArray const&)>::call<QtPrivate::List<QByteArray const&>, void> qobjectdefs_impl.h 169 0x4090ff
10 QtPrivate::QSlotObject<void (VoiceCommandDetector:: *)(QByteArray const&), QtPrivate::List<QByteArray const&>, void>::impl qobject_impl.h 120 0x409069
11 QMetaObject::activate(QObject *, int, int, void * *) 0x7f5e501bdb56
12 VoiceRecorder::chunkRecorded moc_voicerecorder.cpp 140 0x40fd64
13 VoiceRecorder::<lambda(QByteArray)>::operator()(QByteArray) const voicerecorder.cpp 36 0x409502
14 QtPrivate::FunctorCall<QtPrivate::IndexesList<0>, QtPrivate::List, void, VoiceRecorder::startRecording()::<lambda(QByteArray)>>::call(VoiceRecorder::<lambda(QByteArray)> &, void * *) qobjectdefs_impl.h 130 0x409929
15 QtPrivate::Functor<VoiceRecorder::startRecording()::<lambda(QByteArray)>, 1>::call<QtPrivate::List, void>(VoiceRecorder::<lambda(QByteArray)> &, void *, void * *) qobjectdefs_impl.h 240 0x4098d9
16 QtPrivate::QFunctorSlotObject<VoiceRecorder::startRecording()::<lambda(QByteArray)>, 1, QtPrivate::List, void>::impl(int, QtPrivate::QSlotObjectBase *, QObject *, void * *, bool *) qobject_impl.h 168 0x4098a7
17 QMetaObject::activate(QObject *, int, int, void * *) 0x7f5e501bdb56
18 VoiceDevice::dataWritten moc_voicedevice.cpp 127 0x410006
19 VoiceDevice::writeData voicedevice.cpp 31 0x409ff5
20 QIODevice::write(const char *, long long) 0x7f5e500b91ad
21 ?? 0x7f5e510daf86
22 ?? 0x7f5e510db581
23 QMetaObject::activate(QObject *, int, int, void * *) 0x7f5e501bd829
24 QTimer::timeout(QTimer::QPrivateSignal) 0x7f5e501ca0b7
25 QTimer::timerEvent(QTimerEvent *) 0x7f5e501ca3b8
26 QObject::event(QEvent *) 0x7f5e501be823
27 QCoreApplication::notifyInternal2(QObject *, QEvent *) 0x7f5e5019139b
28 QTimerInfoList::activateTimers() 0x7f5e501e590e
29 ?? 0x7f5e501e61c9
30 g_main_context_dispatch 0x7f5e4c8e9197
31 ?? 0x7f5e4c8e93f0
32 g_main_context_iteration 0x7f5e4c8e949c
33 QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) 0x7f5e501e653f
34 QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) 0x7f5e5018f3da
35 QCoreApplication::exec() 0x7f5e50198314
36 main main.cpp 20 0x408c2a

@marcomagdy marcomagdy removed the bug This issue is a bug. label Oct 13, 2017
@justnance justnance added help wanted We are asking the community to submit a PR to resolve this issue. and removed help wanted labels Apr 19, 2019
@github-actions
Copy link

github-actions bot commented Aug 8, 2020

Greetings! Sorry to say but this is a very old issue that is probably not getting as much attention as it deservers. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to open a new one.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-for-staleness help wanted We are asking the community to submit a PR to resolve this issue.
Projects
None yet
Development

No branches or pull requests

4 participants