[Boost-bugs] [Boost C++ Libraries] #13392: deadline_timer -> endless handler recursion, if it should have been cancelled.

Subject: [Boost-bugs] [Boost C++ Libraries] #13392: deadline_timer -> endless handler recursion, if it should have been cancelled.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2018-01-11 10:25:23


#13392: deadline_timer -> endless handler recursion, if it should have been
cancelled.
------------------------------------------------+--------------------------
 Reporter: HeinrichBoost <heinrich_nbongo@…> | Owner:
                                                | chris_kohlhoff
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: asio
  Version: Boost 1.65.0 | Severity: Problem
 Keywords: deadline_timer, hanlder cancelling |
------------------------------------------------+--------------------------
 Following
 http://www.boost.org/doc/libs/1_65_0/doc/html/boost_asio/reference/deadline_timer.html
 example, I made a modification to do a cyclic timer:

 {{{
 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(&MyClass::mDoWorkCallback, this));
 }
 }}}

 Further I have

 {{{
 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);
 }
 }}}

 What happens is not what I expect. If I don't call ''Restart()''
 everything works fine, i.e.'' asyn_wait(handlers)'' are interrupted. But
 If I call once ''Restart()'', and after the call ''expires_from_now'' is
 executed inside, the ''on_timeout'' 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
 ''operation aborted(995)'' as an error argument, i.e. its been
 continuously cancelled).

 I also get **once** an error message when calling ''expires_from_now'' :

 {{{
 operation aborted(995) The I/O operation has been aborted because of
 either a thread exit or an application request
 }}}

 which would mean OK to me : the handler was canceled. But nevertheless it
 continues to be executed.

 The above behavior doesn't occur if I uncomment following code in the
 handler

 if (error)
 {
    return;
 }

 The above seems to me buggy. And to you ?

-- 
Ticket URL: <https://svn.boost.org/trac10/boost/ticket/13392>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2018-01-11 10:30:16 UTC