Boost C++ Libraries: Ticket #11945: Segmentation fault on using boost syslog and cpp-netlib https://svn.boost.org/trac10/ticket/11945 <p> 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. </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;boost/network/protocol/http/client.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/log/utility/setup/file.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/log/sinks/syslog_backend.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">boost</span><span class="o">::</span><span class="n">network</span><span class="p">;</span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">boost</span><span class="o">::</span><span class="n">network</span><span class="o">::</span><span class="n">http</span><span class="p">;</span> <span class="k">namespace</span> <span class="n">sinks</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">log</span><span class="o">::</span><span class="n">sinks</span><span class="p">;</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="n">client</span><span class="o">::</span><span class="n">request</span> <span class="n">request_</span><span class="p">(</span><span class="s">&quot;http://www.boost.org/&quot;</span><span class="p">);</span> <span class="n">client</span> <span class="n">client_</span><span class="p">;</span> <span class="n">client</span><span class="o">::</span><span class="n">response</span> <span class="n">response_</span> <span class="o">=</span> <span class="n">client_</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="n">request_</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">body_</span> <span class="o">=</span> <span class="n">body</span><span class="p">(</span><span class="n">response_</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;body: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">body_</span><span class="p">;</span> <span class="k">using</span> <span class="n">syslog_sinkT</span> <span class="o">=</span> <span class="n">sinks</span><span class="o">::</span><span class="n">synchronous_sink</span> <span class="o">&lt;</span><span class="n">sinks</span><span class="o">::</span><span class="n">syslog_backend</span><span class="o">&gt;</span><span class="p">;</span> <span class="n">boost</span><span class="o">::</span><span class="n">shared_ptr</span> <span class="o">&lt;</span><span class="n">sinks</span><span class="o">::</span><span class="n">syslog_backend</span><span class="o">&gt;</span> <span class="n">backend</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">make_shared</span> <span class="o">&lt;</span><span class="n">sinks</span><span class="o">::</span><span class="n">syslog_backend</span><span class="o">&gt;</span> <span class="p">();</span> <span class="n">boost</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">syslog_sinkT</span><span class="o">&gt;</span> <span class="n">sink</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">make_shared</span> <span class="o">&lt;</span><span class="n">syslog_sinkT</span><span class="o">&gt;</span> <span class="p">(</span><span class="n">backend</span><span class="p">);</span> <span class="p">}</span> </pre></div></div><p> When last 2 lines are commented, segmentation fault disappears and everything works fine. </p> <p> gdb stack trace (approximately, may vary): </p> <pre class="wiki">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=&lt;optimized out&gt;) 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&lt;unsigned int, boost::asio::io_service&gt;::operator() (p=&lt;optimized out&gt;, this=&lt;optimized out&gt;) 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&lt;boost::_bi::value&lt;boost::asio::io_service*&gt; &gt;::operator()&lt;unsigned int, boost::_mfi::mf0&lt;unsigned int, boost::a$ io::io_service&gt;, boost::_bi::list0&gt; (a=&lt;synthetic pointer&gt;, 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&lt;unsigned int, boost::_mfi::mf0&lt;unsigned int, boost::asio::io_service&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;boo$ t::asio::io_service*&gt; &gt; &gt;::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&lt;boost::_bi::bind_t&lt;unsigned int, boost::_mfi::mf0&lt;unsigned int, boost::asio::io_service&gt;, boost::_bi::$ ist1&lt;boost::_bi::value&lt;boost::asio::io_service*&gt; &gt; &gt; &gt;::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 </pre><p> 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. </p> <p> Note 1. Segmentation fault appears inside cpp-netlib before reaching syslog_backend creation. Only presence of last 2 lines guarantees SIGSEGV reproduction. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11945 Trac 1.4.3 Andrey Semashev Thu, 28 Jan 2016 11:25:40 GMT <link>https://svn.boost.org/trac10/ticket/11945#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11945#comment:1</guid> <description> <p> 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. </p> <p> Also, did you report it to cppnetlib devs? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Thu, 28 Jan 2016 11:27:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11945#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11945#comment:2</guid> <description> <p> BTW, you might want to try using the native syslog API in the sink backend. In this case Boost.ASIO won't be used. </p> </description> <category>Ticket</category> </item> <item> <author>c.dovgal@…</author> <pubDate>Thu, 28 Jan 2016 11:34:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11945#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11945#comment:3</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <author>c.dovgal@…</author> <pubDate>Thu, 28 Jan 2016 15:04:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11945#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11945#comment:4</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Thu, 28 Jan 2016 15:13:54 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11945#comment:5 https://svn.boost.org/trac10/ticket/11945#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> 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. </p> Ticket Kostiantyn Dovgal <c.dovgal@…> Thu, 28 Jan 2016 15:38:36 GMT <link>https://svn.boost.org/trac10/ticket/11945#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11945#comment:6</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Thu, 28 Jan 2016 17:10:47 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11945#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11945#comment:7</guid> <description> <p> I don't think <code>BOOST_LOG_USE_NATIVE_SYSLOG</code> 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. </p> </description> <category>Ticket</category> </item> <item> <author>Kostiantyn Dovgal <c.dovgal@…></author> <pubDate>Fri, 29 Jan 2016 12:50:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11945#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11945#comment:8</guid> <description> <p> Yes, i mixed up. It was not about BOOST_LOG_USE_NATIVE_SYSLOG, but BOOST_ASIO_ENABLE_HANDLER_TRACKING. </p> </description> <category>Ticket</category> </item> </channel> </rss>