Open depikaraj opened 6 years ago
Could you attach the full backtrace from GDB, @depikaraj, when compiling for debug with cmake -DCMAKE_BUILD_TYPE=Debug
?
Thanks!
Core was generated by `./helloworld'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 std::operator<< <char, std::char_traits<char>, std::allocator<char> > (__str=<error reading variable: Cannot access memory at address 0x1100>, __os=...)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/bits/basic_string.h:5330
5330 return __ostream_insert(__os, __str.data(), __str.size());
[Current thread is 1 (LWP 1526)]
(gdb) bt
#0 std::operator<< <char, std::char_traits<char>, std::allocator<char> > (__str=<error reading variable: Cannot access memory at address 0x1100>, __os=...)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/bits/basic_string.h:5330
#1 crow::logger::operator<< <std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > (
value=<error reading variable: Cannot access memory at address 0x1100>, this=0x76f95584)
at /crow-0.1/include/crow/logging.h:88
#2 crow::Connection<crow::SocketAdaptor, crow::Crow<>>::complete_request() (this=0x0)
at /crow-0.1/include/crow/http_connection.h:338
#3 0x0002ac10 in std::function<void ()>::operator()() const (this=0x20f958)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/functional:2136
#4 crow::response::end (this=0x20f8e8) at /crow-0.1/include/crow/http_response.h:108
#5 crow::TaggedRule<>::<lambda(const crow::request&, crow::response&)>::operator() (__closure=<optimized out>, res=...)
at /crow-0.1/include/crow/routing.h:475
#6 std::_Function_handler<void(const crow::request&, crow::response&), crow::TaggedRule<Args>::operator()(Func&&) [with Func = main()::<lambda()>; Args = {}; typename std::enable_if<crow::black_magic::CallHelper<Func, crow::black_magic::S<Args ...> >::value, void>::type = void]::<lambda(const crow::request&, crow::response&)> >::_M_invoke(const std::_Any_data &, const crow::request &, crow::response &) (__functor=..., __args#0=..., __args#1=...)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/functional:1740
#7 0x0003e500 in crow::Router::handle (this=0x7ec8dbe4, req=..., res=...)
at /crow-0.1/include/crow/routing.h:1049
#8 0x00046d60 in crow::Crow<>::handle(crow::request const&, crow::response&) (res=..., req=..., this=<optimized out>)
at /crow-0.1/include/crow/app.h:53
#9 crow::Connection<crow::SocketAdaptor, crow::Crow<>>::handle() (this=0x20e758)
at /crow-0.1/include/crow/http_connection.h:321
#10 0x00047644 in crow::HTTPParser<crow::Connection<crow::SocketAdaptor, crow::Crow<>> >::process_message() (this=0x20f770)
at /crow-0.1/include/crow/parser.h:137
#11 crow::HTTPParser<crow::Connection<crow::SocketAdaptor, crow::Crow<>> >::on_message_complete(http_parser*) (self_=<optimized out>)
at /crow-0.1/include/crow/parser.h:86
#12 0x0002f68c in http_parser_execute (parser=0x20f770,
settings=settings@entry=0x4ac64 <crow::HTTPParser<crow::Connection<crow::SocketAdaptor, crow::Crow<>> >::feed(char const*, int)::settings_>,
data=<optimized out>, len=len@entry=76) at /crow-0.1/include/crow/http_parser_merged.h:2081
#13 0x00043748 in crow::HTTPParser<crow::Connection<crow::SocketAdaptor, crow::Crow<>> >::feed(char const*, int) (length=<optimized out>, buffer=<optimized out>,
this=<optimized out>) at /crow-0.1/include/crow/parser.h:109
#14 crow::Connection<crow::SocketAdaptor, crow::Crow<>>::do_read()::{lambda(boost::system::error_code const&, unsigned int)#1}::operator()(boost::system::error_code const&, unsigned int) const (bytes_transferred=<optimized out>, ec=..., __closure=0x76f961fc)
at /crow-0.1/include/crow/http_connection.h:470
#15 boost::asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<>>::do_read()::{lambda(boost::system::error_code const&, unsigned int)#1}, boost::system::error_code, unsigned int>::operator()() (this=0x76f961fc)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/boost/asio/detail/bind_handler.hpp:127
#16 boost::asio::asio_handler_invoke<boost::asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<>>::do_read()::{lambda(boost::system::error_code const&, unsigned int)#1}, boost::system::error_code, unsigned int> >(boost::asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<>>::do_read()::{lambda(boost::system::error_code const&, unsigned int)#1}, boost::system::error_code, unsigned int>&, ...) (function=...)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/boost/asio/handler_invoke_hook.hpp:69
#17 boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<>>::do_read()::{lambda(boost::system::error_code const&, unsigned int)#1}, boost::system::error_code, unsigned int>, {lambda(boost::system::error_code const&, unsigned int)#1}>(boost::asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<>>::do_read()::{lambda(boost::system::error_code const&, unsigned int)#1}, boost::system::error_code, unsigned int>&, {lambda(boost::system::error_code const&, unsigned int)#1}&) (context=..., function=...)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/boost/asio/detail/handler_invoke_helpers.hpp:37
#18 boost::asio::detail::reactive_socket_recv_op<boost::asio::mutable_buffers_1, crow::Connection<crow::SocketAdaptor, crow::Crow<>>::do_read()::{lambda(boost::sys---Type <return> to continue, or q <return> to quit---
tem::error_code const&, unsigned int)#1}>::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned int) (owner=0x20e540,
owner@entry=0x36950 <boost::asio::detail::epoll_reactor::descriptor_state::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned int)+376>, base=base@entry=0x20fa00)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/boost/asio/detail/reactive_socket_recv_op.hpp:110
#19 0x00036950 in boost::asio::detail::task_io_service_operation::complete (bytes_transferred=0, ec=..., owner=..., this=<optimized out>)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/boost/asio/detail/task_io_service_operation.hpp:38
#20 boost::asio::detail::epoll_reactor::descriptor_state::do_complete (
owner=0x36950 <boost::asio::detail::epoll_reactor::descriptor_state::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned int)+376>, owner@entry=0x20e540, base=base@entry=0x75c00470, ec=..., bytes_transferred=1)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/boost/asio/detail/impl/epoll_reactor.ipp:651
#21 0x000403f4 in boost::asio::detail::task_io_service_operation::complete (bytes_transferred=<optimized out>, ec=..., owner=..., this=0x75c00470)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/boost/asio/detail/task_io_service_operation.hpp:38
#22 boost::asio::detail::task_io_service::do_run_one (ec=..., this_thread=..., lock=..., this=0x20e540)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/boost/asio/detail/impl/task_io_service.ipp:372
#23 boost::asio::detail::task_io_service::run (ec=..., this=0x20e540)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/boost/asio/detail/impl/task_io_service.ipp:149
#24 boost::asio::io_service::run (this=<optimized out>)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/boost/asio/impl/io_service.ipp:59
#25 crow::Server<crow::Crow<>, crow::SocketAdaptor>::run()::{lambda()#1}::operator()() const (__closure=0x76f9638c)
at /crow-0.1/include/crow/http_server.h:128
#26 0x0004094c in std::_Bind_simple<crow::Server<crow::Crow<>, crow::SocketAdaptor>::run()::{lambda()#1} ()>::_M_invoke<>(std::_Index_tuple<>) (
this=<optimized out>) at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/functional:1400
#27 std::_Bind_simple<crow::Server<crow::Crow<>, crow::SocketAdaptor>::run()::{lambda()#1} ()>::operator()() (this=<optimized out>)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/functional:1389
#28 std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>, std::_Bind_simple<crow::Server<crow::Crow<>, crow::SocketAdaptor>::run()::{lambda()#1} ()>, void>::operator()() const (this=0x76f96e14)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/future:1347
#29 std::_Function_handler<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> (), std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>, std::_Bind_simple<crow::Server<crow::Crow<>, crow::SocketAdaptor>::run()::{lambda()#1} ()>, void> >::_M_invoke(std::_Any_data const&) (__functor=...)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/functional:1726
#30 0x0002c70c in std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>::operator()() const (
this=<optimized out>) at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/functional:2136
#31 std::__future_base::_State_baseV2::_M_do_set(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*) (this=0x20e634, __f=<optimized out>, __did_set=0x76f96e13)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/future:532
#32 0x4173f17c in __pthread_once_slow (once_control=0x20e644, init_routine=0x29df0 <__once_proxy@plt>) at /usr/src/debug/glibc/2.24-r0/git/nptl/pthread_once.c:116
#33 0x000378e4 in __gthread_once (__func=<optimized out>, __once=0x20e644)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/arm-openbmc-linux-gnueabi/bits/gthr-default.h:699
#34 std::call_once<void (std::__future_base::_State_baseV2::*)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*), std::__future_base::_State_baseV2*, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*>(std::once_flag&, void (std::__future_base::_State_baseV2::*&&)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*), std::__future_base::_State_baseV2*&&, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*&&, bool*&&) (__f=<optimized out>, __once=...)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/mutex:619
#35 std::__future_base::_State_baseV2::_M_set_result(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()---Type <return> to continue, or q <return> to quit---
>, bool) (__ignore_failure=false, __res=..., this=0x20e634) at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/future:392
#36 std::__future_base::_Async_state_impl<std::_Bind_simple<crow::Server<crow::Crow<>, crow::SocketAdaptor>::run()::{lambda()#1} ()>, void>::_Async_state_impl(crow::Server<crow::Crow<>, crow::SocketAdaptor>::run()::{lambda()#1} (&&)())::{lambda()#1}::operator()() const (__closure=0x20e67c)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/future:1663
#37 std::_Bind_simple<std::__future_base::_Async_state_impl<std::_Bind_simple<crow::Server<crow::Crow<>, crow::SocketAdaptor>::run()::{lambda()#1} ()>, void>::_Async_state_impl(crow::Server<crow::Crow<>, crow::SocketAdaptor>::run()::{lambda()#1} (&&)())::{lambda()#1} ()>::_M_invoke<>(std::_Index_tuple<>) (this=0x20e67c)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/functional:1400
#38 std::_Bind_simple<std::__future_base::_Async_state_impl<std::_Bind_simple<crow::Server<crow::Crow<>, crow::SocketAdaptor>::run()::{lambda()#1} ()>, void>::_Async_state_impl(crow::Server<crow::Crow<>, crow::SocketAdaptor>::run()::{lambda()#1} (&&)())::{lambda()#1} ()>::operator()() (this=0x20e67c)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/functional:1389
#39 std::thread::_State_impl<std::_Bind_simple<std::__future_base::_Async_state_impl<std::_Bind_simple<crow::Server<crow::Crow<>, crow::SocketAdaptor>::run()::{lambda()#1} ()>, void>::_Async_state_impl(crow::Server<crow::Crow<>, crow::SocketAdaptor>::run()::{lambda()#1} (&&)())::{lambda()#1} ()> >::_M_run() (this=0x20e678)
at /sysroots/armv6-openbmc-linux-gnueabi/usr/include/c++/6.2.0/thread:196
#40 0x41a201a0 in std::execute_native_thread_routine (__p=0x20e678)
at ../../../../../../../../../../work-shared/gcc-6.2.0-r0/gcc-6.2.0/libstdc++-v3/src/c++11/thread.cc:83
#41 0x41736154 in start_thread (arg=0x76f97450) at /usr/src/debug/glibc/2.24-r0/git/nptl/pthread_create.c:458
#42 0x416b2260 in ?? () at ../sysdeps/unix/sysv/linux/arm/clone.S:86 from /sysroots/armv6-openbmc-linux-gnueabi/lib/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
@netromdk Here is the backtrace for ref. Thanks!
From what I can see is that:
void end()
{
if (!completed_)
{
completed_ = true;
if (complete_request_handler_)
{
complete_request_handler_(); // <-- This gets called in frame 4 in crow/http_response.h:108.
}
}
}
Which invokes crow/http_connection.h:338:
void complete_request()
{
CROW_LOG_INFO << "Response: " << this << ' ' << req_.raw_url << ' ' << res.code << ' ' << close_connection_;
...
But this
is nullptr
!
It also goes through routing.h:1048:
if (rule_index == RULE_SPECIAL_REDIRECT_SLASH)
{
CROW_LOG_INFO << "Redirecting to a url with trailing slash: " << req.url;
res = response(301);
...
Could you try doing wget http://0.0.0.0:8080/
with a trailing slash and see if that doesn't crash, @depikaraj?
@netromdk
Thanks for the reply.
I did try wget http://0.0.0.0:8080/
and it still segfaults.
Try using app.loglevel(crow::LogLevel::Warning)
as a workaround, @depikaraj. It only uses this
when making the INFO log entry.
@netromdk I am new to crow source code. So, when you said "Try using app.loglevel(crow::LogLevel::Warning)" does that mean add it to helloworld.cpp like this
CROW_ROUTE(app.loglevel(crow::LogLevel::Warning), "/").
([]{
return "Hello, world!";
});
This hid the logs while running but still the program segfaulted.
crow::Connection<crow::SocketAdaptor, crow::Crow<>>::complete_request() (this=0x0)
at /crow-0.1/include/crow/http_connection.h:338
if (need_to_call_after_handlers_)
I meant adding that line right after:
crow::SimpleApp app;
But the effect is the same because loglevel()
returns a reference to self.
What needs to be done is finding out why the captured this
is nullptr
. It looks like the captured this
instance goes out of scope but the lambda persists and thus errors. The weird thing is that I don't get this segfault when I do the same thing on my Intel Mac.
@netromdk Thanks for the response. I successfully cross compiled crow server for ARM and currently trying to run the server on it. This is how my cpp looks
#include <crow_all.h>
int main()
{
crow::SimpleApp app;
CROW_ROUTE(app.loglevel(crow::LogLevel::Warning), "/")
([]{
return "Hello, world!";
});
app
.port(8080)
.run();
}
I did try to suppress the logs previously by commenting the #define CROW_ENABLE_LOGGING. Looks like logging isnt the main issue for segfault.
It would be useful to see some extra logging with app.loglevel(crow::LogLevel::Debug)
to see if that reveals anything, @depikaraj.
@netromdk Here's the extra logging.
root@witherspoon:/tmp# ./crow
(2018-02-21 03:59:47) [INFO ] Crow/0.1 server is running at 0.0.0.0:8080 using 1 threads
(2018-02-21 03:59:47) [INFO ] Call `app.loglevel(crow::LogLevel::Warning)` to hide Info level logs.
(2018-02-21 03:59:47) [DEBUG ] Connection open, total 1, 0x193b758
(2018-02-21 03:59:53) [DEBUG ] Connection open, total 2, 0x75c004c8
(2018-02-21 03:59:53) [DEBUG ] 0x193b758 timer cancelled: 0 0
(2018-02-21 03:59:53) [DEBUG ] timer add inside: 0x76f6b474 0
(2018-02-21 03:59:53) [DEBUG ] 0x193b758 timer added: 0x76f6b474 0
(2018-02-21 03:59:53) [DEBUG ] 0x193b758 timer cancelled: 0x76f6b474 0
(2018-02-21 03:59:53) [INFO ] Request: 127.0.0.1:39458 0x193b758 HTTP/1.1 GET /
(2018-02-21 03:59:53) [DEBUG ] Matched rule '/' 1 / 2
Segmentation fault (core dumped)
I used the header crow_all.h from crow-0.1 and compiled hello world example cpp successfully. And the crow server runs on 0.0.0.0:8080. But I get a segmentation fault while trying to access the server using wget. Machine details: Linux witherspoon 4.10.17 armv6l GNU/Linux
root@witherspoon:/tmp# ./crow (2018-02-19 05:12:49) [INFO ] Crow/0.1 server is running at 0.0.0.0:8080 using 1 threads (2018-02-19 05:12:49) [INFO ] Call
app.loglevel(crow::LogLevel::Warning)
to hide Info level logs. (2018-02-19 05:12:57) [INFO ] Request: 127.0.0.1:37350 0x12349f0 HTTP/1.1 GET / Segmentation fault (core dumped)root@witherspoon:~# wget 0.0.0.0:8080 Connecting to 0.0.0.0:8080 (0.0.0.0:8080) wget: error getting response
On running the core file with gdb, the following was reported.
Program terminated with signal SIGSEGV, Segmentation fault.
0 0x00036748 in crow::Connection<crow::SocketAdaptor, crow::Crow<>>::complete_request() (this=0x0)
8973 if (need_to_call_afterhandlers)
Any leads on how to fix this issue? Thanks in advance.