1
Vote

Segfault when accessing http_request

description

Using Ubuntu 14.04 (Linux tinder 3.16.0-60-generic #80~14.04.1-Ubuntu SMP Wed Jan 20 13:37:48 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux) with the C++Resk SDK tag v2.7.0 (debug build), built with boost 1.56

My code kept failing in my ::handle_get(http_request message) functions when I'd call message.reply()

I had run this before, so I checked out my old code, and then some samples, and I get the same issue.

The gdb output below is from the BlackJackServer sample. Steps to reproduce: start the sample, and then with a browser/wget, request that page.
#0  0x000000000072f5d0 in vtable for web::http::details::_http_response ()
#1  0x00000000004a0644 in __gnu_cxx::new_allocator<web::http::details::_http_response>::destroy<web::http::details::_http_response> (this=0x7fffd4000f00, 
    __p=0x7fffd4000f00) at /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/ext/new_allocator.h:124
#2  0x00000000004a0618 in std::allocator_traits<std::allocator<web::http::details::_http_response> >::_S_destroy<web::http::details::_http_response> (__a=..., 
    __p=0x7fffd4000f00) at /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/alloc_traits.h:282
#3  0x00000000004a059d in std::allocator_traits<std::allocator<web::http::details::_http_response> >::destroy<web::http::details::_http_response> (__a=..., 
    __p=0x7fffd4000f00) at /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/alloc_traits.h:411
#4  0x000000000049fa58 in std::_Sp_counted_ptr_inplace<web::http::details::_http_response, std::allocator<web::http::details::_http_response>, (__gnu_cxx::_Lock_policy)2>::_M_dispose (this=0x7fffd4000ef0) at /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr_base.h:524
#5  0x0000000000495515 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x7fffd4000ef0)
    at /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr_base.h:149
#6  0x00007ffff7a3e0cc in std::_Sp_counted_ptr_inplace<pplx::details::_Task_completion_event_impl<web::http::http_response>, std::allocator<pplx::details::_Task_completion_event_impl<web::http::http_response> >, (__gnu_cxx::_Lock_policy)2>::_M_dispose() ()
   from /home/matt/workspace/opal2/o2linux64/Libs/cpprestsdk/2.7.0/lib/libcpprest.so.2.7
#7  0x0000000000495515 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x7fffd4000e60)
    at /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr_base.h:149
#8  0x00007ffff7a2d638 in web::http::details::_http_request::~_http_request() () from /home/matt/workspace/opal2/o2linux64/Libs/cpprestsdk/2.7.0/lib/libcpprest.so.2.7
#9  0x0000000000495515 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x7fffd4000ba0)
    at /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/shared_ptr_base.h:149
#10 0x00007ffff7b44d9f in web::http::experimental::listener::details::connection::handle_http_line(boost::system::error_code const&) ()
   from /home/matt/workspace/opal2/o2linux64/Libs/cpprestsdk/2.7.0/lib/libcpprest.so.2.7
#11 0x00007ffff7b478e8 in boost::asio::detail::read_until_match_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, std::allocator<char>, web::http::experimental::listener::details::crlf_nonascii_searcher_t, web::http::experimental::listener::details::connection::start_request_response()::{lambda(boost::system::error_code const&, unsigned long)#2}>::operator()(boost::system::error_code const&, unsigned long, int) ()
   from /home/matt/workspace/opal2/o2linux64/Libs/cpprestsdk/2.7.0/lib/libcpprest.so.2.7
#12 0x00007ffff7b48f48 in boost::asio::detail::reactive_socket_recv_op<boost::asio::mutable_buffers_1, boost::asio::detail::read_until_match_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, std::allocator<char>, web::http::experimental::listener::details::crlf_nonascii_searcher_t, web::http::experimental::listener::details::connection::start_request_response()::{lambda(boost::system::error_code const&, unsigned long)#2}> >::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned long) ()
   from /home/matt/workspace/opal2/o2linux64/Libs/cpprestsdk/2.7.0/lib/libcpprest.so.2.7
#13 0x00007ffff7a9ce21 in boost::asio::detail::task_io_service::run(boost::system::error_code&) ()
   from /home/matt/workspace/opal2/o2linux64/Libs/cpprestsdk/2.7.0/lib/libcpprest.so.2.7
#14 0x00007ffff7b16626 in crossplat::threadpool::thread_start(void*) () from /home/matt/workspace/opal2/o2linux64/Libs/cpprestsdk/2.7.0/lib/libcpprest.so.2.7
#15 0x00007ffff606d182 in start_thread (arg=0x7fffe35e4700) at pthread_create.c:312
#16 0x00007ffff4f3647d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
I get the same with v2.6.0 (debug build)

Another note, Boost 1.56 seems to throw a lot of warnings with C++RestSDK, so to build it I had to remove the -Werror flag. While we do want to upgrade our version of boost, it's not something I can do right now.

Thanks

UPDATE
The BlackJack sample, and my programs, work when built on another host. i.e. I can build them on another host and copy them over. I still can't identify any differences though. The build commands are identical, the output from ldd is identical, the dependencies were copied from the same place and are identical, libcpprest.sa was even built on the host that is causing me problems.

comments

khea_actua wrote Feb 25, 2016 at 8:00 PM

Discovered the issue. Somehow I had gcc 4.8 and g++ 4.9 installed. Cleaning up this version discrepancy fixed my problem.

No idea how it happened, or why it hasn't manifested before now. :S