chenshuo / muduo

Event-driven network library for multi-threaded Linux server in C++11
https://github.com/chenshuo/muduo
Other
14.88k stars 5.18k forks source link

bug: Timer callbacks may still be invoked even after the timer has been canceled #668

Open jdx2013519 opened 1 year ago

jdx2013519 commented 1 year ago
 callingExpiredTimers_ = true;
 cancelingTimers_.clear();
  for (const Entry& it : expired)
  {
    it.second->run();
  }
  callingExpiredTimers_ = false;

if you cancel the timer in callback, the next timer will still run. so you should try to judge timer if it is in cancelingTimers_ beforn callback

 callingExpiredTimers_ = true;
 cancelingTimers_.clear();
  for (const Entry& it : expired)
  {
// if it is in cancelingtimers
    it.second->run();
  }
  callingExpiredTimers_ = false;
chenshuo commented 1 year ago

Yes, PRs are welcome.