Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#11945 closed Bugs (invalid)

Segmentation fault on using boost syslog and cpp-netlib

Reported by: c.dovgal@… Owned by: Andrey Semashev
Milestone: To Be Determined Component: log
Version: Boost Release Branch Severity: Problem
Keywords: Cc:

Description

After adding boost syslog into source code, segmentation fault appears inside cpp-netlib library. I was able to prepare minimum working code snippet to reproduce the problem.

#include <boost/network/protocol/http/client.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/sinks/syslog_backend.hpp>

#include <iostream>

using namespace boost::network;
using namespace boost::network::http;

namespace sinks = boost::log::sinks;

int main()
{
    client::request request_("http://www.boost.org/");
    client client_;
    client::response response_ = client_.get(request_);
    std::string body_ = body(response_);
    std::cout << "body: " << body_;
    using syslog_sinkT = sinks::synchronous_sink <sinks::syslog_backend>;
    boost::shared_ptr <sinks::syslog_backend> backend = boost::make_shared <sinks::syslog_backend> ();
    boost::shared_ptr<syslog_sinkT> sink = boost::make_shared <syslog_sinkT> (backend);
}

When last 2 lines are commented, segmentation fault disappears and everything works fine.

gdb stack trace (approximately, may vary):

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xf7c29b40 (LWP 19874)]
0x00000000 in ?? ()
(gdb) where
#0  0x00000000 in ?? ()
#1  0x083c376c in boost::asio::detail::task_io_service_operation::complete (bytes_transferred=260, ec=..., owner=..., 
    this=0xf6900710)
    at /home/kostidov/prj/third_party-master/boost/boost_1_60_0/__public__/v0/Linux-libc6/include/boost/asio/detail/task_io_service_o$
eration.hpp:38
#2  boost::asio::detail::task_io_service::do_run_one (ec=..., this_thread=..., lock=..., this=<optimized out>)
    at /home/kostidov/prj/third_party-master/boost/boost_1_60_0/__public__/v0/Linux-libc6/include/boost/asio/detail/impl/task_io_serv$
ce.ipp:372
#3  boost::asio::detail::task_io_service::run (ec=..., this=0x84ea280)
    at /home/kostidov/prj/third_party-master/boost/boost_1_60_0/__public__/v0/Linux-libc6/include/boost/asio/detail/impl/task_io_serv$
ce.ipp:149
#4  boost::asio::io_service::run (this=0x84e9a94)
    at /home/kostidov/prj/third_party-master/boost/boost_1_60_0/__public__/v0/Linux-libc6/include/boost/asio/impl/io_service.ipp:59
#5  0x083b5766 in boost::_mfi::mf0<unsigned int, boost::asio::io_service>::operator() (p=<optimized out>, this=<optimized out>)
    at /home/kostidov/prj/third_party-master/boost/boost_1_60_0/__public__/v0/Linux-libc6/include/boost/bind/mem_fn_template.hpp:49
#6  boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> >::operator()<unsigned int, boost::_mfi::mf0<unsigned int, boost::a$
io::io_service>, boost::_bi::list0> (a=<synthetic pointer>, f=..., this=0x84ea94c)
    at /home/kostidov/prj/third_party-master/boost/boost_1_60_0/__public__/v0/Linux-libc6/include/boost/bind/bind.hpp:249
#7  boost::_bi::bind_t<unsigned int, boost::_mfi::mf0<unsigned int, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boo$
t::asio::io_service*> > >::operator() (this=0x84ea944)
    at /home/kostidov/prj/third_party-master/boost/boost_1_60_0/__public__/v0/Linux-libc6/include/boost/bind/bind.hpp:1222
#8  boost::detail::thread_data<boost::_bi::bind_t<unsigned int, boost::_mfi::mf0<unsigned int, boost::asio::io_service>, boost::_bi::$
ist1<boost::_bi::value<boost::asio::io_service*> > > >::run (this=0x84ea828)
    at /home/kostidov/prj/third_party-master/boost/boost_1_60_0/__public__/v0/Linux-libc6/include/boost/thread/detail/thread.hpp:116
#9  0x0840a4f8 in boost::(anonymous namespace)::thread_proxy (param=0x84ea828) at libs/thread/src/pthread/thread.cpp:167
#10 0xf7de1f70 in start_thread () from /lib/i386-linux-gnu/libpthread.so.0
#11 0xf7d18bee in clone () from /lib/i386-linux-gnu/libc.so.6

Problem exists on Ubuntu 14.04 with cpp-netlib 0.11.2 and both boost versions 1_58_0 and 1_60_0. Boost, cpp-netlib and my application are compiled with -std=c++11. GCC versions which were used: 4.8.4, 5.2.0.

Note 1. Segmentation fault appears inside cpp-netlib before reaching syslog_backend creation. Only presence of last 2 lines guarantees SIGSEGV reproduction.

Change History (8)

comment:1 by Andrey Semashev, 7 years ago

Both Boost.Log and cppnetlib use Boost.ASIO for network operations. Are you sure both libraries use the same version of Boost.ASIO? Other than that I don't see the relation between the two libraries.

Also, did you report it to cppnetlib devs?

comment:2 by Andrey Semashev, 7 years ago

BTW, you might want to try using the native syslog API in the sink backend. In this case Boost.ASIO won't be used.

comment:3 by c.dovgal@…, 7 years ago

Yes, I'm sure that the version is the same. No, I haven't reported it to cpp-netlib yet. Also I was able to test on Mac OS X (boost_1_57_0) and it works fine there.

comment:4 by c.dovgal@…, 7 years ago

Ok. I used quite a lot additional key for compiling both boost and cpp-netlib before. After building them from scratch once again with minimum additional compiling options, the problem disappears. So I think this ticket can be closed. If I get some more information, I'll update this ticket with it.

comment:5 by Andrey Semashev, 7 years ago

Resolution: invalid
Status: newclosed

If you define any configuration macros for Boost.ASIO, make sure they are consistently defined when compiling all components - your application, Boost.Log and cppnetlib.

comment:6 by Kostiantyn Dovgal <c.dovgal@…>, 7 years ago

I found the key which causes the error. It's BOOST_LOG_USE_NATIVE_SYSLOG It was defined during the boost compilation, but wasn't defined during compilation of cpp-netlib and my application. Thank you for a hint.

comment:7 by Andrey Semashev, 7 years ago

I don't think BOOST_LOG_USE_NATIVE_SYSLOG is the real culprit as it just enables use of the native syslog API and has no effect on Boost.ASIO. But anyway, I'm glad you solved the problem.

comment:8 by Kostiantyn Dovgal <c.dovgal@…>, 7 years ago

Yes, i mixed up. It was not about BOOST_LOG_USE_NATIVE_SYSLOG, but BOOST_ASIO_ENABLE_HANDLER_TRACKING.

Note: See TracTickets for help on using tickets.