Boost C++ Libraries: Ticket #6006: Potential epoll fd leak in boost::asio::detail::epoll_reactor https://svn.boost.org/trac10/ticket/6006 <p> in boost/asio/detail/epoll_reactor.hpp: </p> <blockquote> <p> <em> Constructor. epoll_reactor(boost::asio::io_service&amp; io_service) </em></p> <blockquote> <p> : boost::asio::detail::service_base&lt;epoll_reactor&lt;Own_Thread&gt; &gt;(io_service), </p> <blockquote> <p> mutex_(), epoll_fd_(do_epoll_create()), ------&gt; epoll_fd_ may leak if the following member's initialization throws an exception wait_in_progress_(false), interrupter_(), ------&gt; may throw because of EMFILE read_op_queue_(), write_op_queue_(), except_op_queue_(), pending_cancellations_(), stop_thread_(false), thread_(0), shutdown_(false), need_epoll_wait_(true) </p> </blockquote> </blockquote> <p> { </p> <blockquote> <p> <em> Start the reactor's internal thread only if needed. if (Own_Thread) { </em></p> <blockquote> <p> boost::asio::detail::signal_blocker sb; thread_ = new boost::asio::detail::thread( </p> <blockquote> <p> bind_handler(&amp;epoll_reactor::call_run_thread, this)); </p> </blockquote> </blockquote> <p> } </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> <em> Add the interrupter's descriptor to epoll. epoll_event ev = { 0, { 0 } }; ev.events = EPOLLIN | EPOLLERR; ev.data.fd = interrupter_.read_descriptor(); epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, interrupter_.read_descriptor(), &amp;ev); </em></p> </blockquote> <p> } </p> </blockquote> <p> and in 1.47.0, there is a similar situation: epoll_fd_ and timer_fd_ may leak. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6006 Trac 1.4.3 yafei.zhang@… Tue, 11 Oct 2011 03:16:43 GMT attachment set https://svn.boost.org/trac10/ticket/6006 https://svn.boost.org/trac10/ticket/6006 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">epoll_reactor.hpp.patch_1.40.0</span> </li> </ul> Ticket yafei.zhang@… Tue, 11 Oct 2011 03:17:34 GMT attachment set https://svn.boost.org/trac10/ticket/6006 https://svn.boost.org/trac10/ticket/6006 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">fd_leak_test.cpp</span> </li> </ul> Ticket yafei.zhang@… Tue, 11 Oct 2011 03:20:53 GMT <link>https://svn.boost.org/trac10/ticket/6006#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6006#comment:1</guid> <description> <p> my patch only works, but it is not graceful enough. wrapping epoll_fd and timer_fd or other tricks? </p> <p> fd_leak_test.cpp is a program reproducing the leak. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Sat, 15 Oct 2011 23:55:26 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6006#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6006#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/74953" title="Construct interrupter member first to fix exception safety issue. Refs ...">[74953]</a>) Construct interrupter member first to fix exception safety issue. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6006" title="#6006: Bugs: Potential epoll fd leak in boost::asio::detail::epoll_reactor (closed: fixed)">#6006</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Mon, 17 Oct 2011 11:32:31 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6006#comment:3 https://svn.boost.org/trac10/ticket/6006#comment:3 <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">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/75009" title="Merge from trunk: * Make number of strand implementations ...">[75009]</a>) Merge from trunk: </p> <ul><li>Make number of strand implementations configurable by defining BOOST_ASIO_STRAND_IMPLEMENTATIONS to the number. </li></ul><ul><li>Programs can now define BOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION to switch the allocation of strand implementations to use a round-robin approach rather than hashing. </li></ul><ul><li>Fix potential strand starvation issue that can occur when strand.post() is used. </li></ul><ul><li>Update descriptor state allocation in kqueue_reactor to match approach used in epoll_reactor. </li></ul><ul><li>Construct epoll_reactor's interrupter member first to fix exception safety issue. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6006" title="#6006: Bugs: Potential epoll fd leak in boost::asio::detail::epoll_reactor (closed: fixed)">#6006</a> </li></ul><ul><li>Clarify that the read operation ends when the buffer is full. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5999" title="#5999: Bugs: boost::asio::async_read with completion_condition strange behavior ... (closed: fixed)">#5999</a> </li></ul> Ticket