bitly/pynsq — pull request #31 by jehiah (2013-06-12 17:12:29+00:00)
Title: Reader Stall during backoff when handling multiple tasks

The code introduced by #28 improved backoff handling. There was an edge case where a reader would not exit backoff state if there were connections for multiple tasks in a reader object.

From Reader.py line [232-238](https://github.com/bitly/pynsq/blob/master/nsq/Reader.py#L238)
```
conn_idx = random.randrange(len(self.conns))
for i, task_conn in enumerate(task_conn for task_conn in self.conns.itervalues() if task_conn.task == task):
...
if i == conn_idx:
... delay RDY 1
```

The problem is that a random connection is picked to get the RDY 1 to leave backoff, but that decision is made before the connection list is filtered to the current task.

cc: @mreiferson @mynameisfiber