Opened 11 years ago

Closed 11 years ago

#6006 closed Bugs (fixed)

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 (2)

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

Download all attachments as: .zip

Change History (5)

by yafei.zhang@…, 11 years ago

by yafei.zhang@…, 11 years ago

Attachment: fd_leak_test.cpp added

comment:1 by yafei.zhang@…, 11 years ago

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 by chris_kohlhoff, 11 years ago

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

comment:3 by chris_kohlhoff, 11 years ago

Resolution: fixed
Status: newclosed

(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
Note: See TracTickets for help on using tickets.