Permalink
Browse files

fix infinite loop in heartbeat dispatch when system time is changed (c…

…loses #428)
  • Loading branch information...
1 parent 61095b4 commit 1427a2c80c401d841194132a9af15baefd68b5ae @tmm1 tmm1 committed Apr 2, 2013
Showing with 12 additions and 0 deletions.
  1. +12 −0 ext/em.cpp
View
@@ -382,15 +382,27 @@ EventMachine_t::_DispatchHeartbeats
void EventMachine_t::_DispatchHeartbeats()
{
+ // Store the first processed heartbeat descriptor and bail out if
+ // we see it again. This fixes an infinite loop in case the system time
+ // is changed out from underneath MyCurrentLoopTime.
+ const EventableDescriptor *head = NULL;
+
while (true) {
multimap<uint64_t,EventableDescriptor*>::iterator i = Heartbeats.begin();
if (i == Heartbeats.end())
break;
if (i->first > MyCurrentLoopTime)
break;
+
EventableDescriptor *ed = i->second;
+ if (ed == head)
+ break;
+
ed->Heartbeat();
QueueHeartbeat(ed);
+
+ if (head == NULL)
+ head = ed;
}
}

0 comments on commit 1427a2c

Please sign in to comment.