Boost C++ Libraries: Ticket #9203: asio::strand allocation algorithm causes handlers to execute on the wrong strand. https://svn.boost.org/trac10/ticket/9203 <p> Hi. </p> <p> We recently updated from boost::asio::1.41 to boost::asio::1.53. We immediately noticed several unittests failing with socket write timeouts and initially didn't think too much of it. However after further investigation we believe that the strand implementation allocation algorithm in strand_service.ipp is the cause of these issues. </p> <p> The allocation algorithm is causing deadlocks/starvation because strand_service::construct can and does provide a strand_service::implementation_type which is currently in use by another io_service::strand. </p> <p> This results in handlers wrapped on io_service::strand-a being executed on io_service::strand-b. If the previous handler executing on io_service::strand-b blocks or delays the handler which should be running on io_service::strand-a will be delayed or never execute. </p> <p> I have attached a sample which will demonstrate this issue: </p> <ul><li>Modify stand.hpp to make the members public (for debug printing). </li><li>Compile as 'g++ -g main.cpp -lboost_thread -lpthread -lboost_system'. </li><li>The example should run forever printing from the 'printer' and 'blocker'. After a little time the 'printer' will stop printing because the condition has been reached. </li></ul><p> I have tested that it demonstrates the issue correctly in ubuntu 10.04/13.04 as well as on an ARM target (Linux (none) 2.6.35.3-dt.0.55121+ <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1" title="#1: Bugs: boost.build causes ftjam to segfault (closed: Wont Fix)">#1</a> Mon Dec 17 12:06:28 EST 2012 armv5tejl GNU/Linux). </p> <p> The issue occurs with any version of boost from 1.42 (including trunk@86189). </p> <p> This is not just a unittest issue for us. We have a TCP server accepting connections and performing async_reads/async_writes on the connection. In the same process we have another thread creating connections to the server and sending/receiving using blocking reads/writes with raw sockets (auto generated code by gSoap). Both the client and server side use strands to sequence their relative operations. Frequently the stand belonging to the connection handler on the server side is given the same implementation of the strand owned by the client side. Deadlock ensues until the client times out (20 seconds). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9203 Trac 1.4.3 Greg Barron <gregbarron71@…> Mon, 07 Oct 2013 02:44:09 GMT attachment set https://svn.boost.org/trac10/ticket/9203 https://svn.boost.org/trac10/ticket/9203 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">main.cpp</span> </li> </ul> <p> Demonstrates strand allocation issue. </p> Ticket anonymous Wed, 23 Oct 2013 22:21:35 GMT version changed https://svn.boost.org/trac10/ticket/9203#comment:1 https://svn.boost.org/trac10/ticket/9203#comment:1 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.54.0</span> → <span class="trac-field-new">Boost 1.55.0</span> </li> </ul> Ticket chris_kohlhoff Mon, 05 May 2014 07:32:05 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9203#comment:2 https://svn.boost.org/trac10/ticket/9203#comment:2 <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> <a class="changeset" href="https://svn.boost.org/trac10/changeset/86464" title="Add a note to clarify that concurrent invocation is not guaranteed for ...">r86464</a> added an additional note in the documentation to make it clearer that a strand makes no guarantee of concurrency. Included in boost 1.55. </p> Ticket