Boost C++ Libraries: Ticket #6800: endless loop in dev_poll_reactor on Solaris when using async_write with more than 65536 bytes https://svn.boost.org/trac10/ticket/6800 <p> The following example-program puts io_service thread in a tight endless loop on Solaris when the server is trying to send more than 65536 bytes (the server and client have to be running on a different host) and client is running. truss on server process shows following calls continuously. </p> <pre class="wiki">/6: recvmsg(57, 0xFFFFFD7FEB9FDDF0, 0) Err#11 EAGAIN /6: write(13, " 9\0\0\019\0\0\0", 8) = 8 /6: ioctl(13, DP_POLL, 0xFFFFFD7FEB9FE460) = 1 /6: recvmsg(57, 0xFFFFFD7FEB9FDDF0, 0) Err#11 EAGAIN /6: write(13, " 9\0\0\019\0\0\0", 8) = 8 /6: ioctl(13, DP_POLL, 0xFFFFFD7FEB9FE460) = 1 /6: recvmsg(57, 0xFFFFFD7FEB9FDDF0, 0) Err#11 EAGAIN /6: write(13, " 9\0\0\019\0\0\0", 8) = 8 /6: ioctl(13, DP_POLL, 0xFFFFFD7FEB9FE460) = 1 /6: recvmsg(57, 0xFFFFFD7FEB9FDDF0, 0) Err#11 EAGAIN /6: write(13, " 9\0\0\019\0\0\0", 8) = 8 /6: ioctl(13, DP_POLL, 0xFFFFFD7FEB9FE460) = 1 /6: recvmsg(57, 0xFFFFFD7FEB9FDDF0, 0) Err#11 EAGAIN /6: write(13, " 9\0\0\019\0\0\0", 8) = 8 /6: ioctl(13, DP_POLL, 0xFFFFFD7FEB9FE460) = 1 </pre><p> The busy-wait loop continues until we stop the client. </p> <p> Here is the server code. I've just changed boost asynchronous TCP daytime server sample to return the specified number of bytes message instead of daytime and put the client connection in read mode. </p> <pre class="wiki">#include &lt;ctime&gt; #include &lt;iostream&gt; #include &lt;cstdlib&gt; #include &lt;string&gt; #include &lt;boost/bind.hpp&gt; #include &lt;boost/shared_ptr.hpp&gt; #include &lt;boost/enable_shared_from_this.hpp&gt; #include &lt;boost/lexical_cast.hpp&gt; #include &lt;boost/asio.hpp&gt; #include &lt;boost/scoped_array.hpp&gt; using boost::asio::ip::tcp; std::string make_message(unsigned int message_size) { using namespace std; std::string data(message_size, 'A'); return data; } class tcp_connection : public boost::enable_shared_from_this&lt;tcp_connection&gt; { public: typedef boost::shared_ptr&lt;tcp_connection&gt; pointer; static pointer create(boost::asio::io_service&amp; io_service, unsigned int message_size) { return pointer(new tcp_connection(io_service, message_size)); } tcp::socket&amp; socket() { return socket_; } void handleMessage(const boost::system::error_code&amp; message_error) { if (message_error) { std::cout&lt;&lt;"Error while reading the message from client"&lt;&lt;std::endl; } else { std::cout&lt;&lt;"Read the message from client"&lt;&lt;std::endl; } } void start() { // Perform async_read on client connection to read data from the client. _header.reset(new char[6]); _header[5] = '\0'; boost::asio::async_read(socket_, boost::asio::buffer(_header.get(), 5), boost::bind(&amp;tcp_connection::handleMessage, shared_from_this(), boost::asio::placeholders::error)); message_ = make_message(message_size_); boost::asio::async_write(socket_, boost::asio::buffer(message_), boost::bind(&amp;tcp_connection::handle_write, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); } private: tcp_connection(boost::asio::io_service&amp; io_service, int message_size) : socket_(io_service), message_size_(message_size) { } void handle_write(const boost::system::error_code&amp; /*error*/, size_t bytes_transferred) { std::cout&lt;&lt;"Bytes written: "&lt;&lt; bytes_transferred &lt;&lt; std::endl; } tcp::socket socket_; std::string message_; boost::scoped_array&lt;char&gt; _header; unsigned int message_size_; }; class tcp_server { public: tcp_server(boost::asio::io_service&amp; io_service, unsigned int port, unsigned int message_size) : acceptor_(io_service, tcp::endpoint(tcp::v4(), port)), message_size_(message_size) { start_accept(); } private: void start_accept() { tcp_connection::pointer new_connection = tcp_connection::create(acceptor_.get_io_service(), message_size_); acceptor_.async_accept(new_connection-&gt;socket(), boost::bind(&amp;tcp_server::handle_accept, this, new_connection, boost::asio::placeholders::error)); } void handle_accept(tcp_connection::pointer new_connection, const boost::system::error_code&amp; error) { if (!error) { new_connection-&gt;start(); start_accept(); } } tcp::acceptor acceptor_; unsigned int message_size_; }; int main(int argc, char* argv[]) { if (argc != 3) { std::cerr &lt;&lt; "Usage: server port message_size" &lt;&lt; std::endl; return 1; } unsigned int port = boost::lexical_cast&lt;unsigned int&gt;(argv[1]); unsigned int message_size = boost::lexical_cast&lt;unsigned int&gt;(argv[2]); try { boost::asio::io_service io_service; tcp_server server(io_service, port, message_size); io_service.run(); } catch (std::exception&amp; e) { std::cerr &lt;&lt; e.what() &lt;&lt; std::endl; } return 0; } </pre><p> For the client we can use boost synchronous TCP daytime client sample (changed to accept port as an argument) . </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/array.hpp&gt; #include &lt;boost/asio.hpp&gt; using boost::asio::ip::tcp; int main(int argc, char* argv[]) { try { if (argc != 3) { std::cerr &lt;&lt; "Usage: client &lt;host&gt; &lt;port&gt;" &lt;&lt; std::endl; return 1; } boost::asio::io_service io_service; tcp::resolver resolver(io_service); tcp::resolver::query query(argv[1], argv[2]); tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); tcp::resolver::iterator end; tcp::socket socket(io_service); boost::system::error_code error = boost::asio::error::host_not_found; while (error &amp;&amp; endpoint_iterator != end) { socket.close(); socket.connect(*endpoint_iterator++, error); } if (error) throw boost::system::system_error(error); for (;;) { boost::array&lt;char, 128&gt; buf; boost::system::error_code error; size_t len = socket.read_some(boost::asio::buffer(buf), error); if (error == boost::asio::error::eof) break; // Connection closed cleanly by peer. else if (error) throw boost::system::system_error(error); // Some other error. std::cout.write(buf.data(), len); } } catch (std::exception&amp; e) { std::cerr &lt;&lt; e.what() &lt;&lt; std::endl; } return 0; } </pre><p> Here is how I ran the server and client on two different solaris hosts - </p> <pre class="wiki">server 9081 200000 client &lt;server_host&gt; 9081 </pre><p> After running the server and client, do "truss" on server which will be showing tight polling loop as mentioned above. </p> <p> The program works fine on Linux and works fine on Solaris when compiled with the flag -DBOOST_ASIO_DISABLE_DEV_POLL. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6800 Trac 1.4.3 anonymous Mon, 16 Apr 2012 14:43:35 GMT component changed; owner set https://svn.boost.org/trac10/ticket/6800#comment:1 https://svn.boost.org/trac10/ticket/6800#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">chris_kohlhoff</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">asio</span> </li> </ul> Ticket samm@… Mon, 16 Apr 2012 15:47:16 GMT keywords set https://svn.boost.org/trac10/ticket/6800#comment:2 https://svn.boost.org/trac10/ticket/6800#comment:2 <ul> <li><strong>keywords</strong> solaris added </li> </ul> Ticket samm@… Mon, 16 Apr 2012 15:47:44 GMT cc set https://svn.boost.org/trac10/ticket/6800#comment:3 https://svn.boost.org/trac10/ticket/6800#comment:3 <ul> <li><strong>cc</strong> <span class="trac-author">samm@…</span> added </li> </ul> Ticket