Opened 9 years ago
Last modified 9 years ago
#8861 new Bugs
boost 1.39 io_service_pool accept hangs
Reported by: | Owned by: | chris_kohlhoff | |
---|---|---|---|
Milestone: | To Be Determined | Component: | asio |
Version: | Boost 1.39.0 | Severity: | Problem |
Keywords: | Cc: |
Description
O.S.: Centos 5.4 64 bit Boost version: 1.39 Symptom: With io_service-per-CPU and thread pool size 4, after the sever accepted at 8th connection, it cannot accept any connections afterwards.
How to reproduce it: (1) Get the server2 example at http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/example/http/server2/
(2) Modify connection.cpp to support persistent connection: void connection::handle_write(const boost::system::error_code& e) {
if (!e) {
Initiate graceful connection closure. boost::system::error_code ignored_ec; socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec); start();
}
(3) Modify the server.cpp to use different acceptor_ constructor server::server(const std::string& address, const std::string& port,
const std::string& doc_root, std::size_t io_service_pool_size)
: io_service_pool_(io_service_pool_size),
acceptor_(io_service_pool_.get_io_service()),
acceptor_( io_service_pool_.get_io_service(),
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), atoi(port.c_str()))),
new_connection_(new connection(
io_service_pool_.get_io_service(), request_handler_)),
request_handler_(doc_root)
{
Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
/*
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 1025); acceptor_.open(endpoint.protocol()); acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); acceptor_.bind(endpoint); acceptor_.listen();
*/
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&server::handle_accept, this,
boost::asio::placeholders::error));
}
(4) The client test harness create threads each second. In the thread, it will connect to the server, send a request and receive the response (both request/response should be small enough for one read/write). After that, the thread will sleep 1000 seconds without closing the connection.
(5) The server cannot accept any connections after 8th requests.
Added the test harness and modification to the server2 example as an attachment