Modify

Ticket #6006 (closed Bugs: fixed)

Opened 3 years ago

Last modified 3 years ago

Potential epoll fd leak in boost::asio::detail::epoll_reactor

Reported by: yafei.zhang@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.40.0 Severity: Problem
Keywords: Cc:

Description

in boost/asio/detail/epoll_reactor.hpp:

Constructor. epoll_reactor(boost::asio::io_service& io_service)

: boost::asio::detail::service_base<epoll_reactor<Own_Thread> >(io_service),

mutex_(), epoll_fd_(do_epoll_create()), ------> epoll_fd_ may leak if the following member's initialization throws an exception wait_in_progress_(false), interrupter_(), ------> 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)

{

Start the reactor's internal thread only if needed. if (Own_Thread) {

boost::asio::detail::signal_blocker sb; thread_ = new boost::asio::detail::thread(

bind_handler(&epoll_reactor::call_run_thread, this));

}

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(), &ev);

}

and in 1.47.0, there is a similar situation: epoll_fd_ and timer_fd_ may leak.

Attachments

epoll_reactor.hpp.patch_1.40.0 Download (855 bytes) - added by yafei.zhang@… 3 years ago.
fd_leak_test.cpp Download (1.1 KB) - added by yafei.zhang@… 3 years ago.

Change History

Changed 3 years ago by yafei.zhang@…

Changed 3 years ago by yafei.zhang@…

comment:1 Changed 3 years ago by yafei.zhang@…

my patch only works, but it is not graceful enough. wrapping epoll_fd and timer_fd or other tricks?

fd_leak_test.cpp is a program reproducing the leak.

comment:2 Changed 3 years ago by chris_kohlhoff

(In [74953]) Construct interrupter member first to fix exception safety issue. Refs #6006

comment:3 Changed 3 years ago by chris_kohlhoff

  • Status changed from new to closed
  • Resolution set to fixed

(In [75009]) Merge from trunk:

  • Make number of strand implementations configurable by defining BOOST_ASIO_STRAND_IMPLEMENTATIONS to the number.
  • 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.
  • Fix potential strand starvation issue that can occur when strand.post() is used.
  • Update descriptor state allocation in kqueue_reactor to match approach used in epoll_reactor.
  • Construct epoll_reactor's interrupter member first to fix exception safety issue. Fixes #6006
  • Clarify that the read operation ends when the buffer is full. Fixes #5999
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.