Opened 5 years ago
Last modified 5 years ago
#13392 new Bugs
deadline_timer -> endless handler recursion, if it should have been cancelled.
Reported by: | Owned by: | chris_kohlhoff | |
---|---|---|---|
Milestone: | To Be Determined | Component: | asio |
Version: | Boost 1.65.0 | Severity: | Problem |
Keywords: | deadline_timer, hanlder cancelling | Cc: | heinrich_nbongo@… |
Description
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 ?