Boost C++ Libraries: Ticket #13392: deadline_timer -> endless handler recursion, if it should have been cancelled. https://svn.boost.org/trac10/ticket/13392 <p> Following <a href="http://www.boost.org/doc/libs/1_65_0/doc/html/boost_asio/reference/deadline_timer.html">http://www.boost.org/doc/libs/1_65_0/doc/html/boost_asio/reference/deadline_timer.html</a> example, I made a modification to do a cyclic timer: </p> <pre class="wiki">void MyClass::on_timeout() { // Here I rely on the documentation, which states that: // basic_deadline_timer::expires_at (2 of 3 overloads) : // // **Any pending asynchronous wait operations will be cancelled.** // // that is no need for // // if (error) // { // return; // } mTimer.expires_at(mTimer.expires_at() + boost::posix_time::seconds(2)); mTimer.async_wait(on_timeout); mIoService.post(boost::bind(&amp;MyClass::mDoWorkCallback, this)); } </pre><p> Further I have </p> <pre class="wiki">void MyClass::Restart() { // Here I rely on the documentation, which states that: // basic_deadline_timer::expires_from_now (2 of 3 overloads) : // // **Any pending asynchronous wait operations will be cancelled.** // mTimer.expires_from_now(boost::posix_time::seconds(2)); mTimer.async_wait(on_timeout); } </pre><p> What happens is not what I expect. If I don't call <em>Restart()</em> everything works fine, i.e.<em> asyn_wait(handlers)</em> are interrupted. But If I call once <em>Restart()</em>, and after the call <em>expires_from_now</em> is executed inside, the <em>on_timeout</em> handler is called in an endless recursion regardless the time value of the timer. For example, value is 5 seconds, but the handler is called many times in a millisecond (with <em>operation aborted(995)</em> as an error argument, i.e. its been continuously cancelled). </p> <p> I also get <strong>once</strong> an error message when calling <em>expires_from_now</em> : </p> <pre class="wiki">operation aborted(995) The I/O operation has been aborted because of either a thread exit or an application request </pre><p> which would mean OK to me : the handler was canceled. But nevertheless it continues to be executed. </p> <p> The above behavior doesn't occur if I uncomment following code in the handler </p> <p> if (error) { </p> <blockquote> <p> return; </p> </blockquote> <p> } </p> <p> The above seems to me buggy. And to you ? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13392 Trac 1.4.3 HeinrichBoost <heinrich_nbongo@…> Thu, 11 Jan 2018 10:57:32 GMT cc set https://svn.boost.org/trac10/ticket/13392#comment:1 https://svn.boost.org/trac10/ticket/13392#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">heinrich_nbongo@…</span> added </li> </ul> Ticket