question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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):

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
marc1ncommented, Dec 18, 2018

This is probably race condition. PubSub object is not thread safe (as described here). Instance of PubSub class should be used in one thread only or access to it from multi threads must be synchronized.

I think the same rule applies to celery.backends.redis.RedisBackend object.

0reactions
github-actions[bot]commented, Dec 18, 2020

This issue is marked stale. It will be closed in 30 days if it is not updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dictionary changed size during iteration" error? - Stack Overflow
This way you iterate over the original dictionary fields and on the fly can change the desired dict d . It works on...
Read more >
RuntimeError: dictionary changed size during iteration · Issue ...
I used the GitHub search to find a similar issue and didn't find it. I searched the FastAPI documentation, with the integrated search....
Read more >
RuntimeError: dictionary changed size during iteration
The Python RuntimeError: dictionary changed size during iteration occurs when we change the size of a dictionary when iterating over it.
Read more >
Filtering Dictionary In Python 3. “RuntimeError - codeburst
RuntimeError: Dictionary changed size during iteration”, Python slaps you in your face when you try to add/remove entries in dict object during iteration....
Read more >
dictionary changed size during iteration" error? : r/learnpython
I'm trying to make a spreadsheet-type program using tkinter. In the end it should be able to add and remove rows/columns by pressing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found