Connection Issues with Redis
I have a celery instance running as a worker process on heroku with heroku redis. About every minute (the amount of time after which heroku redis kills idle connections) this comes up in my logs:
Dec 12 14:34:40 app/worker.1: [2015-12-12 16:34:40,387: WARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...
Dec 12 14:34:40 app/worker.1: Traceback (most recent call last):
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/celery/worker/consumer.py", line 278, in start
Dec 12 14:34:40 app/worker.1: blueprint.start(self)
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/celery/bootsteps.py", line 123, in start
Dec 12 14:34:40 app/worker.1: step.start(parent)
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/celery/worker/consumer.py", line 821, in start
Dec 12 14:34:40 app/worker.1: c.loop(*c.loop_args())
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/celery/worker/loops.py", line 76, in asynloop
Dec 12 14:34:40 app/worker.1: next(loop)
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/async/hub.py", line 285, in create_loop
Dec 12 14:34:40 app/worker.1: poll_timeout = fire_timers(propagate=propagate) if scheduled else 1
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/async/hub.py", line 144, in fire_timers
Dec 12 14:34:40 app/worker.1: entry()
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/async/timer.py", line 64, in __call__
Dec 12 14:34:40 app/worker.1: return self.fun(*self.args, **self.kwargs)
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/async/timer.py", line 132, in _reschedules
Dec 12 14:34:40 app/worker.1: return fun(*args, **kwargs)
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/redis.py", line 322, in maybe_restore_messages
Dec 12 14:34:40 app/worker.1: num=channel.unacked_restore_limit,
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/redis.py", line 188, in restore_visible
Dec 12 14:34:40 app/worker.1: self.unacked_mutex_expire):
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/contextlib.py", line 17, in __enter__
Dec 12 14:34:40 app/worker.1: return self.gen.next()
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/redis.py", line 112, in Mutex
Dec 12 14:34:40 app/worker.1: i_won = client.setnx(name, lock_id)
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/redis/client.py", line 1097, in setnx
Dec 12 14:34:40 app/worker.1: return self.execute_command('SETNX', name, value)
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/redis/client.py", line 575, in execute_command
Dec 12 14:34:40 app/worker.1: connection.disconnect()
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/redis.py", line 819, in disconnect
Dec 12 14:34:40 app/worker.1: channel._on_connection_disconnect(self)
Dec 12 14:34:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/redis.py", line 476, in _on_connection_disconnect
Dec 12 14:34:40 app/worker.1: raise get_redis_ConnectionError()
Dec 12 14:34:40 app/worker.1: ConnectionError
Dec 12 14:34:40 app/worker.1: [2015-12-12 16:34:40,452: INFO/MainProcess] Connected to redis://h:**@***************:********//
Dec 12 14:34:40 app/worker.1: [2015-12-12 16:34:40,480: INFO/MainProcess] mingle: searching for neighbors
Dec 12 14:34:41 app/worker.1: [2015-12-12 16:34:41,535: INFO/MainProcess] mingle: all alone
This is a recent phenomenon, it started last night and isn't foiled by a process restart. Could this possibly be a result of any updates or the like?
Running python 2.7.11 amqp==1.4.8 anyjson==0.3.3 billiard==3.3.0.22 celery==3.1.19 kombu==3.0.30 pytz==2015.7 redis==2.10.5 Django==1.8.7 django-redis-cache==1.6.5
Try installing: pip install -U https://github.com/celery/kombu/zipball/3.0#egg=kombu
I will prepare a release with this fix shortly
Getting a 404 on the URL (tried curl and pip)
https://github.com/celery/kombu/zipball/3.0#egg=kombu
I appreciate the work, it didn't really solve the problem but I've since stopped using Heroku redis in production which seems to have been the trick.
I'm still getting this error.
File "/webapps/sp_cabinet/local/lib/python2.7/site-packages/redis/connection.py", line 921, in disconnect
connection.disconnect()
File "/webapps/sp_cabinet/local/lib/python2.7/site-packages/kombu/transport/redis.py", line 835, in disconnect
channel._on_connection_disconnect(self)
File "/webapps/sp_cabinet/local/lib/python2.7/site-packages/kombu/transport/redis.py", line 491, in _on_connection_disconnect
raise get_redis_ConnectionError()
ConnectionError
[2015-12-21 22:42:49,168: INFO/MainProcess] Connected to redis://localhost:6379/0
celery==3.1.19 kombu==3.0.32 redis==2.10.5 Django==1.6.5
On start everythng is OK. Worker handles tasks and periodically loses connection. Then connection recovers and tasks keep handling. I noticed that connection loses exactly when new task comes.
I'm experiencing this as well, same as OP, but with kombu==3.0.32
Setting the server connection timeout to 0 (no timeout) "fixed" the issue, at least for the past few days. However, that doesn't seem sustainable, because the # of connections keeps rising (since not all clients always close their connections, at least on Heroku).
So if I understand the root issue correctly, Celery's reconnect after the server closes the connection isn't working correctly. (Unfortunately I'm not sure why).
Is there any other debug info that would be helpful?
Other commenters have joined, figured re-opening this was appropriate.
have this problem
I just ran a bunch of tests, and can confirm that the bug reported by OP was introduced in 3.0.30 (it doesn't happen for me with 3.0.29, does happen with 3.0.30, 31, 32).
To repro, I set the Heroku redis server timeout to something very short (10 seconds) and tried my app with the various versions of kombu pinned (3.0.29 - 3.0.32, omitting 3.0.31 since it had that localhost bug).
Looking at the changelog, between that and the actual traceback (see below), 60edf5626545539472e1ca1b7714e3cf33b8ea4d looks to be the commit in question (though I assume that change was made for a reason, so just reverting would be unwise!)
My traceback for 3.0.29 is identical to the OP; for 3.0.32, it's as follows:
Dec 23 13:33:40 app/worker.1: consumer: Connection to broker lost. Trying to re-establish the connection...
Dec 23 13:33:40 app/worker.1: Traceback (most recent call last):
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/celery/worker/consumer.py", line 278, in start
Dec 23 13:33:40 app/worker.1: blueprint.start(self)
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/celery/bootsteps.py", line 123, in start
Dec 23 13:33:40 app/worker.1: step.start(parent)
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/celery/worker/consumer.py", line 821, in start
Dec 23 13:33:40 app/worker.1: c.loop(*c.loop_args())
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/celery/worker/loops.py", line 76, in asynloop
Dec 23 13:33:40 app/worker.1: next(loop)
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/async/hub.py", line 340, in create_loop
Dec 23 13:33:40 app/worker.1: cb(*cbargs)
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/redis.py", line 991, in on_readable
Dec 23 13:33:40 app/worker.1: self._callbacks[queue](message)
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/virtual/__init__.py", line 534, in _callback
Dec 23 13:33:40 app/worker.1: self.qos.append(message, message.delivery_tag)
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/redis.py", line 148, in append
Dec 23 13:33:40 app/worker.1: dumps([message._raw, EX, RK])) \
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/redis/client.py", line 2628, in execute
Dec 23 13:33:40 app/worker.1: conn.disconnect()
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/redis.py", line 835, in disconnect
Dec 23 13:33:40 app/worker.1: channel._on_connection_disconnect(self)
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/redis.py", line 489, in _on_connection_disconnect
Dec 23 13:33:40 app/worker.1: self._disconnect_pools()
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/redis.py", line 477, in _disconnect_pools
Dec 23 13:33:40 app/worker.1: self._async_pool.disconnect()
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/redis/connection.py", line 921, in disconnect
Dec 23 13:33:40 app/worker.1: connection.disconnect()
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/redis.py", line 835, in disconnect
Dec 23 13:33:40 app/worker.1: channel._on_connection_disconnect(self)
Dec 23 13:33:40 app/worker.1: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/redis.py", line 491, in _on_connection_disconnect
Dec 23 13:33:40 app/worker.1: raise get_redis_ConnectionError()
Dec 23 13:33:40 app/worker.1: ConnectionError
Dec 23 13:33:40 app/worker.1: Connected to redis://h:**@*******:*****//
Dec 23 13:33:40 app/worker.1: mingle: searching for neighbors
Dec 23 13:33:41 app/worker.1: mingle: all alone
@alexkahn did you switch to a non-Heroku redis, or away from redis entirely? (Trying to figure out if the issue is specific to Heroku).
Could you please try this patch?
A bit quick there, the two patches please :)
Sorry, having a hard time getting this to install on Heroku from requirements.txt
-e git://github.com/celery/kombu.git@7fc856cffc16a0af93e5227f845e2a8ba93b2a31#egg=kombu
doesn't work. I'll just vendor it - it'll take me a few minutes (everything's a bit more complicated w/Heroku).
I need to step away right now, but will be able to give this a proper test in a few hours. Thanks for all your work!
Hot tip: Don't use git, use the github zipballs feature:
http://github.com/celery/kombu/zipball/master#egg=kombu
without the -e
Sorry for the delay - same error, unfortunately.
@kgrinberg I just moved off of Heroku Redis - I think their configuration of Redis with hard connection timeouts was the root of the issue but I am still using Redis for messaging.
Getting the issue here too with kombu==3.0.32, I had upgraded from 3.0.29. I'm reverting to 3.0.29.
have this problem too. My environment is following: celery 3.1.19 redis 2.10.5 kombu 3.0.32
@kgrinberg That's odd, using the master branch with celery 3.1 cannot possibly work at all, so did you port the patch over?
@ask Gah. You're absolutely right. My apologies. I didn't notice it at first because of how Heroku caches eggs.
I redeployed to a "clean" app and got the expected error. Would you suggest trying the master branch with celery 4rc1, or can you port the patch to the 3.0 branch? (Or I can do it, probably tomorrow).
@kgrinberg I just ported it now, please try: pip install https://github.com/celery/kombu/zipball/3.0 :)