ask/celery — Issue #531: redis.exceptions.ConnectionError when trying to add a lot of tasks to redis backend
Author: kevin1024
Created: 2011-11-10 00:07:29+00:00
State: open

I'm trying to rapidly add a lot of tasks, using redis backend. Several go through, then I get an exception (see Traceback below)

# Software Versions
celery version 2.4.1
kombu version 1.4.3
pyredis 2.4.10
redis version 2.0.3 (newest in EPEL repo)
linux version Red Hat Enterprise Linux Server release 5.6 (Tikanga)

# References
Someone else with a similar problem:
http://groups.google.com/group/celery-users/browse_thread/thread/b14d469de5877798

Related redis issue:
https://github.com/antirez/hiredis/issues/58

# Code to reproduce
```python
from celery.task import task

@task
def do_nothing(i):
print i
import time;time.sleep(5)

NUM_ITERATIONS = 10000

for i in range(NUM_ITERATIONS):
do_nothing.delay(i)

```

# Celeryconfig (all options probably not necessary to reproduce, but this is what I'm using in production and that's where I see the problem)
```python
BROKER_HOST = "localhost"
BROKER_BACKEND = "redis"
REDIS_HOST = "localhost"
CELERYD_PREFETCH_MULTIPLIER = 1
CELERY_IMPORTS = ("pulley.tasks",)
CELERY_TRACK_STARTED = True
CELERY_DISABLE_RATE_LIMITS = True
CELERY_IGNORE_RESULT = True
CELERY_SEND_TASK_ERROR_EMAILS = False
```

# Traceback
```
Traceback (most recent call last):
File "tasks2.py", line 11, in
do_nothing.delay(i)
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/celery/app/task/__init__.py", line 338, in delay
return self.apply_async(args, kwargs)
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/celery/app/task/__init__.py", line 444, in apply_async
publish = publisher or self.app.amqp.publisher_pool.acquire(block=True)
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/kombu/connection.py", line 637, in acquire
resource = self.prepare(self.new())
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/kombu/pools.py", line 51, in prepare
p = p()
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/kombu/pools.py", line 42, in
return lambda: self.create_producer()
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/celery/app/amqp.py", line 264, in create_producer
pub = self.app.amqp.TaskPublisher(conn, auto_declare=False)
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/celery/app/amqp.py", line 325, in TaskPublisher
return TaskPublisher(*args, **self.app.merge(defaults, kwargs))
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/celery/app/amqp.py", line 157, in __init__
super(TaskPublisher, self).__init__(*args, **kwargs)
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/kombu/compat.py", line 44, in __init__
self.backend = connection.channel()
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/kombu/connection.py", line 159, in channel
chan = self.transport.create_channel(self.connection)
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/kombu/connection.py", line 560, in connection
self._connection = self._establish_connection()
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/kombu/connection.py", line 521, in _establish_connection
conn = self.transport.establish_connection()
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/kombu/transport/virtual/__init__.py", line 671, in establish_connection
self._avail_channels.append(self.create_channel(self))
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/kombu/transport/virtual/__init__.py", line 654, in create_channel
channel = self.Channel(connection)
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/kombu/transport/pyredis.py", line 144, in __init__
self.client.info()
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/redis/client.py", line 339, in info
return self.execute_command('INFO')
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/kombu/transport/pyredis.py", line 347, in execute_command
conn.send_command(*args)
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/redis/connection.py", line 242, in send_command
self.send_packed_command(self.pack_command(*args))
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/redis/connection.py", line 225, in send_packed_command
self.connect()
File "/var/apps/.virtualenvs/pulley/lib/python2.6/site-packages/redis/connection.py", line 173, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 99 connecting localhost:6379. Cannot assign requested address.
```