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

pplx::task ContinuationTaskHandle exception causing crash #1763

Open
przcub opened this issue Jul 27, 2023 · 1 comment
Open

pplx::task ContinuationTaskHandle exception causing crash #1763

przcub opened this issue Jul 27, 2023 · 1 comment

Comments

@przcub
Copy link

przcub commented Jul 27, 2023

Hi,
In our production code we are getting crash and looking for some support with finding root cause.
Any advice is more than welcome
libcpprest in version 2.10.

#0  0x0000007f796b9c9c in raise () from /.../lib/libpthread.so.0
No symbol table info available.
#1  0x0000005589813fdc in pplx::details::_ExceptionHolder::~_ExceptionHolder (this=<optimized out>, this=<optimized out>) at /.../usr/include/pplx/pplxtasks.h:952
No locals.
#2  0x00000055897e2d78 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x7f683b9c90) at /.../usr/include/c++/9.3.0/bits/shared_ptr_base.h:148
No locals.
#3  std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x7f683b9c90) at /.../usr/include/c++/9.3.0/bits/shared_ptr_base.h:148
No locals.
#4  std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (this=<optimized out>, this=<optimized out>) at /.../usr/include/c++/9.3.0/bits/shared_ptr_base.h:730
No locals.
#5  std::__shared_ptr<pplx::details::_ExceptionHolder, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=<optimized out>, this=<optimized out>) at /.../usr/include/c++/9.3.0/bits/shared_ptr_base.h:1169
No locals.
#6  std::shared_ptr<pplx::details::_ExceptionHolder>::~shared_ptr (this=<optimized out>, this=<optimized out>) at /.../usr/include/c++/9.3.0/bits/shared_ptr.h:103
No locals.
#7  pplx::details::_Task_impl_base::~_Task_impl_base (this=<optimized out>, this=<optimized out>) at /.../usr/include/pplx/pplxtasks.h:1718
No locals.
#8  pplx::details::_Task_impl<unsigned char>::~_Task_impl (this=<optimized out>, this=<optimized out>) at /.../usr/include/pplx/pplxtasks.h:2425
No locals.
#9  __gnu_cxx::new_allocator<pplx::details::_Task_impl<unsigned char> >::destroy<pplx::details::_Task_impl<unsigned char> > (this=<optimized out>, __p=<optimized out>)
    at /.../usr/include/c++/9.3.0/ext/new_allocator.h:153
No locals.
#10 std::allocator_traits<std::allocator<pplx::details::_Task_impl<unsigned char> > >::destroy<pplx::details::_Task_impl<unsigned char> > (__a=..., __p=<optimized out>)
    at /.../usr/include/c++/9.3.0/bits/alloc_traits.h:497
No locals.
#11 std::_Sp_counted_ptr_inplace<pplx::details::_Task_impl<unsigned char>, std::allocator<pplx::details::_Task_impl<unsigned char> >, (__gnu_cxx::_Lock_policy)2>::_M_dispose (this=0x7f683c11e0)
    at /.../usr/include/c++/9.3.0/bits/shared_ptr_base.h:557
No locals.
#12 0x0000005589752524 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x7f682afc80) at /.../usr/include/c++/9.3.0/bits/shared_ptr_base.h:155
No locals.
#13 std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x7f682afc80) at /.../usr/include/c++/9.3.0/bits/shared_ptr_base.h:148
No locals.
#14 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (this=<optimized out>, this=<optimized out>) at /.../usr/include/c++/9.3.0/bits/shared_ptr_base.h:730
No locals.
#15 std::__shared_ptr<pplx::details::_Task_impl<unsigned char>, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=<optimized out>, this=<optimized out>) at /.../usr/include/c++/9.3.0/bits/shared_ptr_base.h:1169
No locals.
#16 std::shared_ptr<pplx::details::_Task_impl<unsigned char> >::~shared_ptr (this=<optimized out>, this=<optimized out>) at /.../usr/include/c++/9.3.0/bits/shared_ptr.h:103
No locals.
#17 pplx::details::_PPLTaskHandle<unsigned char, pplx::task<web::http::http_response>::_ContinuationTaskHandle<web::http::http_response, void, CWebHTTPClient::doRequest(const string&, const string&, const string&, IHTTPClient::RequestCallback_t)::<lambda(const pplx::task<web::http::http_response>&)>, std::integral_constant<bool, true>, pplx::details::_TypeSelectorNoAsync>, pplx::details::_ContinuationTaskHandleBase>::~_PPLTaskHandle (this=<optimized out>, this=<optimized out>)
    at /.../usr/include/pplx/pplxtasks.h:1628
No locals.
#18 pplx::task<web::http::http_response>::_ContinuationTaskHandle<web::http::http_response, void, CWebHTTPClient::doRequest(const string&, const string&, const string&, IHTTPClient::RequestCallback_t)::<lambda(const pplx::task<web::http::http_response>&)>, std::integral_constant<bool, true>, pplx::details::_TypeSelectorNoAsync>::~_ContinuationTaskHandle (this=<optimized out>, this=<optimized out>) at /.../usr/include/pplx/pplxtasks.h:3927
No locals.
#19 pplx::task<web::http::http_response>::_ContinuationTaskHandle<web::http::http_response, void, CWebHTTPClient::doRequest(const string&, const string&, const string&, IHTTPClient::RequestCallback_t)::<lambda(const pplx::task<web::http::http_response>&)>, std::integral_constant<bool, true>, pplx::details::_TypeSelectorNoAsync>::~_ContinuationTaskHandle(void) (this=<optimized out>, this=<optimized out>) at /.../usr/include/pplx/pplxtasks.h:3927
No locals.
#20 0x0000007f7ad62954 in boost::asio::detail::completion_handler<boost::_bi::bind_t<void, void (*)(void*), boost::_bi::list1<boost::_bi::value<void*> > > >::do_complete(void*, boost::asio::detail::scheduler_operation*, boost::system::error_code const&, unsigned long)
    () from /.../usr/lib/libcpprest.so.2.10
No symbol table info available.
#21 0x0000007f7ace04d8 in ?? () from /.../usr/lib/libcpprest.so.2.10
No symbol table info available.
#22 0x0000007f7ad63738 in ?? () from /.../usr/lib/libcpprest.so.2.10
No symbol table info available.
#23 0x0000007f7acc940c in ?? () from /.../usr/lib/libcpprest.so.2.10
No symbol table info available.
#24 0x0000007f796ae4c8 in ?? () from /.../lib/libpthread.so.0
No symbol table info available.
#25 0x0000007f794298fc in ?? () from /.../lib/libc.so.6
No symbol table info available.

Piece of code

void CWebHTTPClient::doRequest( const std::string &url, const std::string &method, const std::string &payload,
                                IHTTPClient::RequestCallback_t callback )
{
    auto httpMethod = web::http::methods::GET;
    if( "POST" == method )
    {
        httpMethod = web::http::methods::POST;
    }
    web::http::client::http_client client( url, createConfig() );
    web::http::http_request request = std::move( createRequest( payload, method ) );
    client.request( request ).then( [url, callback]( const pplx::task< web::http::http_response > &responseTask )
    {
        auto responseTaskData = responseTask.get();
        auto code = responseTaskData.status_code();

        const auto ignoreContentType = true;
        responseTaskData.extract_string( ignoreContentType ).then( [code, url, callback] ( const pplx::task< utility::string_t > &bodyTask )
        {
            const auto body = utility::conversions::to_utf8string( bodyTask.get() );
            IHTTPClient::Response_t response;
            response.code = static_cast<HTTPCode> ( code );
            response.responseBody = body;

            callback( response );
        } );
    } );
}

web::http::http_request CWebHTTPClient::createRequest( const std::string &payload, const std::string &method ) const noexcept
{
    web::http::http_request request( method );
    request.headers().add( std::string( "Content-Type" ), std::string( "application/json" ) );

    if( web::http::methods::POST == method && !payload.empty() )
    {
        request.headers().add( std::string( "Content-Length" ), payload.size() );
        request.set_body( payload );
    }
    return request;
}

web::http::client::http_client_config CWebHTTPClient::createConfig() const noexcept
{
    web::http::client::http_client_config config;
    config.set_timeout( std::chrono::milliseconds( CWebHTTPClient::DEFAULT_TIMEOUT_MS ) );
    return config;
}
@ignacionr
Copy link

Hi! Sorry just another dev here, not part of the team. Wanted to say you are probably misunderstanding the Concurrency library. You may probably resolve your issue by just adding .wait() to the client.request().then() chain.

Other than that, the code in general seems way too verbose, please consider using a more modern C++ style, which will get you the benefit of easier reading and thus, getting actions and probable issue causes front and center.

Just my 2cts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants