【问题标题】:SIGSEGV on Boost UDP socket close - tcache_get at malloc.cSIGSEGV on Boost UDP socket close - tcache_get at malloc.c
【发布时间】:2018-10-10 19:51:56
【问题描述】:

我不知道这个问题可能来自哪里: (使用 GDB 调试):

terminate called after throwing an instance of '[Thread 0x7ffff5e68700 (LWP 24945) exited]
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'

线程 1“random_walkerta”收到信号 SIGSEGV,分段错误。 malloc.c:2943 处的 tcache_get (tc_idx=1)

堆栈跟踪:

#0  tcache_get (tc_idx=1) at malloc.c:2943
#1  __GI___libc_malloc (bytes=31) at malloc.c:3050
#2  0x00007ffff6ec154c in operator new(unsigned long) ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff6f56dbf in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_mutate(unsigned long, unsigned long, char const*, unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff6f584bb in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long) ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00005555555bee66 in boost::system::system_error::what (
    this=0x5555558a1bf0) at /usr/include/boost/system/system_error.hpp:70
#6  0x00007ffff6eba8ba in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x00007ffff6ec0d3a in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#8  0x00007ffff6ebfd59 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#9  0x00007ffff6ec0708 in __gxx_personality_v0 ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#10 0x00007ffff6888763 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#11 0x00007ffff688907d in _Unwind_Resume ()
   from /lib/x86_64-linux-gnu/libgcc_s.so.1
#12 0x00005555555cb8d6 in boost::asio::detail::do_throw_error (err=..., 
    location=0x555555610dba "close")
    at /usr/include/boost/asio/detail/impl/throw_error.ipp:37
---Type <return> to continue, or q <return> to quit---
#13 0x00005555555cb741 in boost::asio::detail::throw_error (err=..., 
    location=0x555555610dba "close")
    at /usr/include/boost/asio/detail/throw_error.hpp:42
#14 0x00005555555de022 in boost::asio::basic_socket<boost::asio::ip::udp, boost::asio::datagram_socket_service<boost::asio::ip::udp> >::close (
    this=0x555555887ea0) at /usr/include/boost/asio/basic_socket.hpp:356
#15 0x00005555555d7ebe in Vast::net_overhearing_handler::handle_close (
    this=0x555555889490) at net_overhearing_handler.cpp:160
#16 0x00005555555d7e4c in Vast::net_overhearing_handler::close (
    this=0x555555889490) at net_overhearing_handler.cpp:141
#17 0x00005555555c9b85 in Vast::net_overhearing::stop (this=0x5555558870e0)
    at net_overhearing.cpp:88
#18 0x00005555555ba77f in Vast::VASTnet::~VASTnet (this=0x55555587f180, 
    __in_chrg=<optimized out>) at VASTnet.cpp:63
#19 0x000055555556ca7a in Vast::destroyNet (net=0x55555587f180)
    at VASTVerse.cpp:93
#20 0x000055555556d036 in Vast::VASTVerse::~VASTVerse (this=0x55555587e4c0, 
    __in_chrg=<optimized out>) at VASTVerse.cpp:196
#21 0x000055555556bce4 in main (argc=1, argv=0x7fffffffe598)
    at random_walkertalker.cpp:266

设置如下: 我有一个在单独的线程 io_service 上运行的 Boost UDP 套接字,监听数据包。在我尝试关闭程序、UDP 套接字和 io_service 之前,一切都按预期工作。我猜我没有正确关闭某些东西。

这里是关闭 UDP 和 io_services 的代码:

if (_io_service != NULL) {
   _io_service->reset();
   _udp->close();                 //This line is giving the error (160)  


   _io_service->stop();
   _iosthread->join();
}

启动时,我执行以下操作:

_udp = new ip::udp::socket(*_io_service);
_udp->open(ip::udp::v4());

_udp->async_receive_from(
  boost::asio::buffer(_buf, VAST_BUFSIZ), _remote_endpoint_,
  boost::bind(&net_overhearing_handler::handle_input, this,
  boost::asio::placeholders::error,
  boost::asio::placeholders::bytes_transferred));

_iosthread = new boost::thread(boost::bind(&boost::asio::io_service::run, io_service));

【问题讨论】:

    标签: c++ sockets boost-asio


    【解决方案1】:

    删除这一行

     _io_service->reset();
    

    因为根据参考io_service::reset

    当有任何未完成的调用时,此函数不得调用 到 run()、run_one()、poll() 或 poll_one() 函数。

    当您调用restart 时,似乎run 方法在线程中有效。

    你不需要调用这个方法来停止io_service::run 方法。 run 中的所有待处理操作将通过调用 _io_service-&gt;stop(); 来取消,然后 run 停止并且您的线程也终止。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-25
      • 1970-01-01
      • 1970-01-01
      • 2016-05-28
      • 2012-11-14
      相关资源
      最近更新 更多