Skip to content

Commit

Permalink
Fix infinite loop in create_loop
Browse files Browse the repository at this point in the history
fixes celery/celery#3712 

Before handling the todo items we "freeze" them by copying them aside and clearing the list.
This way if an item in the todo list appends a new callable to the list itself it will be taken care of in the next iteration of the parent loop instead of producing an infinite loop by adding it to the list we're running on.
  • Loading branch information
gabriel-amram committed Jul 9, 2017
1 parent ad54980 commit 25db0b1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions kombu/async/hub.py
Expand Up @@ -269,13 +269,18 @@ def create_loop(self,
consolidate = self.consolidate
consolidate_callback = self.consolidate_callback
on_tick = self.on_tick
todo = self._ready
propagate = self.propagate_errors

while 1:
for tick_callback in on_tick:
tick_callback()


# To avoid infinite loop where one of the callables adds items to self._ready
# (via call_soon or otherwise), we copy the todo list aside and clear the _ready
# so items added don't affect this loop and instead they'll be taken care of on the
# next itermation of the parent-loop
todo = self._ready.copy()
self._ready.clear()
while todo:
item = todo.pop()
if item:
Expand Down

0 comments on commit 25db0b1

Please sign in to comment.