Skip to content

"Dictionary changed size during iteration" in client.PubSub.on_connect() #968

@jyunis

Description

@jyunis

Hi!

I'm using:
celery==4.1.0
redis==2.10.6

On a fairly busy backend, and I'm seeing occasional 'dictionary changed size during iteration' (full trace below) errors during times of peak load. My guess is that this happens when PubSub.subscribe() and PubSub.on_connect() are called concurrently (thereby changing self.channels as on_connect() iterates over it.

https://github.com/andymccurdy/redis-py/blob/5109cb4f6b610e8d5949716a16435afbbf35075a/redis/client.py#L2376

RuntimeError: dictionary changed size during iteration
File "celery/app/task.py", line 413, in delay
return self.apply_async(args, kwargs)
File "celery/app/task.py", line 536, in apply_async
**options
File "celery/app/base.py", line 736, in send_task
self.backend.on_task_call(P, task_id)
File "celery/backends/redis.py", line 189, in on_task_call
self.result_consumer.consume_from(task_id)
File "celery/backends/redis.py", line 76, in consume_from
self._consume_from(task_id)
File "celery/backends/redis.py", line 82, in _consume_from
self._pubsub.subscribe(key)
File "redis/client.py", line 2482, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2404, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2415, in _execute
connection.connect()
File "redis/connection.py", line 502, in connect
callback(self)
File "redis/client.py", line 2374, in on_connect
for k, v in iteritems(self.channels):

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions