Repository navigation
Open
Description
I'm using Celery version 4.0.2
When using Redis as the backend, I've been observing TimeoutError exception waiting on a .get() of a celery task.
The issue is intermittent. Roughly, 1/30 cases exhibit the issue
From the logs, I observe that the task has finished successfully and therefore, I expect to see the result stored in the backend and available for the client. However, the client never receives that result, and instead, raises a TimeoutError.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/celery-4.0.2-py2.7.egg/celery/result.py", line 189, in get
on_message=on_message,
File "/usr/local/lib/python2.7/site-packages/celery-4.0.2-py2.7.egg/celery/backends/async.py", line 189, in wait_for_pending
for _ in self._wait_for_pending(result, **kwargs):
File "/usr/local/lib/python2.7/site-packages/celery-4.0.2-py2.7.egg/celery/backends/async.py", line 256, in _wait_for_pending
on_interval=on_interval):
File "/usr/local/lib/python2.7/site-packages/celery-4.0.2-py2.7.egg/celery/backends/async.py", line 57, in drain_events_until
yield self.wait_for(p, wait, timeout=1)
File "/usr/local/lib/python2.7/site-packages/celery-4.0.2-py2.7.egg/celery/backends/async.py", line 66, in wait_for
wait(timeout=timeout)
File "/usr/local/lib/python2.7/site-packages/celery-4.0.2-py2.7.egg/celery/backends/redis.py", line 69, in drain_events
m = self._pubsub.get_message(timeout=timeout)
File "build/bdist.linux-x86_64/egg/redis/client.py", line 2260, in get_message
response = self.parse_response(block=False, timeout=timeout)
File "build/bdist.linux-x86_64/egg/redis/client.py", line 2183, in parse_response
return self._execute(connection, connection.read_response)
File "build/bdist.linux-x86_64/egg/redis/client.py", line 2165, in _execute
return command(*args)
File "build/bdist.linux-x86_64/egg/redis/connection.py", line 577, in read_response
response = self._parser.read_response()
File "build/bdist.linux-x86_64/egg/redis/connection.py", line 238, in read_response
response = self._buffer.readline()
File "build/bdist.linux-x86_64/egg/redis/connection.py", line 168, in readline
self._read_from_socket()
File "build/bdist.linux-x86_64/egg/redis/connection.py", line 139, in _read_from_socket
raise TimeoutError("Timeout reading from socket")
TimeoutError: Timeout reading from socket
Reacted by Andri Rizhakov, Dejan Lekić, Jun Makii, danhruby, Meduzik, Nick Johnson, Areeb Jamal, Giuliano P. Tognarelli Buono-core, Nicolas Crocfer, straumboi and 8 more
Activity
hp685 commentedon May 23, 2017
Additionally, I'm using the following package versions
amqp (2.1.4)
billiard (3.5.0.2)
celery (4.0.2)
hiredis (0.2.0)
redis (2.10.5)
redis-collections (0.1.7)
arizhakov commentedon Jan 7, 2018
Are there any ideas on possible solutions? An idea is to try to increase the socket timeout. Another idea I had was to catch the specific error and reattempt the task.
What would be recommended by celery contributors/developers? Any additional diagnostics that could help? Thanks!
auvipy commentedon Aug 12, 2018
whats the update of the issue on with the latest release of celery?
auvipy commentedon Aug 12, 2018
report if this still exists
dejlek commentedon Aug 24, 2018
Yes, this is still an issue...
hp685 commentedon Aug 28, 2018
I'm now using amqp backend but I can switch back to redis & report back if the issue still exists with Celery 4.2.1.
crabhi commentedon Nov 22, 2018
Hi, I think I'm facing the same issue. I can open a new one if you think it's different.
I've found the issue when testing RedisLabs Cloud instance as a broker and backend. Intentionally, I connected via public Internet with ping around 15 ms to the AWS datacenter and some packet loss.
Under these conditions, I observe that sometimes the
result.get(timeout=X)call times out even if I'm able to query the Redis database and retrieve the key when theget()is blocked.Application:
Network settings: 20% packet loss, 10ms delay
Calling code:
Worker log ends with:
These lines appear and roughly after 60s, the calling code times out.
Database
The database can be queried any time after the log lines appear in the worker log.
Timeout on a fresh connectionEven after Python restart, Celery isn't able to get the result:EDIT: This isn't true. I was trying different backend URLs and was connecting to a wrong one. The rest still holds.
PIP versions
auvipy commentedon Nov 22, 2018
please try celery and kombu from master branch and report again here
crabhi commentedon Nov 22, 2018
Thank you for your reply. I'll do it (I plan it for Tuesday).
auvipy commentedon Nov 22, 2018
install all the celery dependencies along with celery from master. if the issue still persists will reopen it.
crabhi commentedon Nov 27, 2018
Hi, I can confirm the issue with
masterbranch and 2% simulated packet loss.40 remaining items
ooyamatakehisa commentedon Sep 5, 2023
@auvipy I have the same issue as well. Someone said using mutex fix this issue (comment) but isn't
get()method process-safe?I'm using celery with django (10 gunicorn workers). I have the issue in #7028 too but if this is the cause, this might be also the reason for this discussion.
balazshornacsek commentedon Mar 23, 2024
I just discovered this with our prod. workers. Any fix yet?
metheoryt commentedon Apr 4, 2024
Same problem, using celery 5.4.0rc1 with django, Redis as a broker.
From pod logs, I can see that these failures corellate with how much requests was done in that period. More requests - more timeouts.
Traceback
celery report
pip freeze
hhhyunwoo commentedon Jul 22, 2024
Any more updates on this timeout issue?
Could it be caused by race condition due to using fastAPI?
dejlek commentedon Jan 29, 2025
We are hitting this issue every now and then... :(
cemysf commentedon Mar 6, 2025
same here, any updates from anyone?
melarcand commentedon Apr 7, 2025
also encountering this same issue and looking for updates.