You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Worker hangs at startup when running without mingle and gossip and many messages in queue #1847
If I enqueue a number of tasks, and then start a worker with --without-mingle and --without-gossip, the worker seems to hang and not actually run any of the tasks I enqueued. I'm running this on debian. On my dev box I have pretty consistently been able to cause the worker to "wake up" and start consuming tasks by issuing a 'celery inspect' command. 'celery inspect active' will return something like:
-> [email protected]: OK
- empty -
And then worker the will go through the tasks.
It appears that the amqp client is stalling (has data in internal buffers, but the hub doesn't know about it). I have identified the commit adding buffering in pyamqp Connection object to this commit: celery/py-amqp@737fa58
@sabw8217 You can test this fix by using 'pyamqp://' broker protocol (in case you have librabbitmq installed). Don't forget to install the code from the 2 PRs mentioned above.
I think there is still an issue here - it looks to me like what it is happening is that this call in asynloop() on line 41 of celery/worker/loops.py can receive messages up to the entire prefetch count of the worker in addition to the basic_consume_ok.
consumer.consume()
And when that happens the messages end up in the method_queue in the amqp Channel. If the entire prefetch count has been received, RMQ won't send anything to us until a message gets acked, but because RMQ isn't sending anything the socket FD never becomes ready to read, and we never end up calling the task handler(which would call drain_events and kick us out of this bad state, where there are prefetch_count basic_deliver messages in the pyamqp's internal method queue). It looks to me like doing this will fix it, but I'm guessing there should be a timeout on this call, and possibly this whole issue should be being addressed at a lower level:
diff --git a/celery/worker/loops.py b/celery/worker/loops.py
index 0891f51..a5ac57a 100644
--- a/celery/worker/loops.py
+++ b/celery/worker/loops.py
@@ -49,6 +49,11 @@ def asynloop(obj, connection, consumer, blueprint, hub, qos,
if not obj.restart_count and not obj.pool.did_start_ok():
raise WorkerLostError('Could not start worker processes')
+ # consumer.consume() may have prefetched up to our
+ # limit - drain an event so we are in a clean state
+ # prior to starting our event loop.
+ connection.drain_events()
+
# FIXME: Use loop.run_forever
# Tried and works, but no time to test properly before release.
hub.propagate_errors = errors
Activity
ionelmc commentedon Feb 6, 2014
Some syscalls while this is happening:
ionelmc commentedon Feb 6, 2014
Stacktrace
ionelmc commentedon Feb 6, 2014
Nevermind.
ionelmc commentedon Feb 6, 2014
Ok so I've patched kombu a bit to have some extra logging:
ionelmc commentedon Feb 6, 2014
Fds to worker processes are from 4 to 13 (inclusive). It looks none of those are added in the hub for writing purpose (thus tasks don't get run).
ionelmc commentedon Feb 8, 2014
It appears that the amqp client is stalling (has data in internal buffers, but the hub doesn't know about it). I have identified the commit adding buffering in pyamqp Connection object to this commit: celery/py-amqp@737fa58
Don't read from the socket more than requested. This prevents stallin…
Don't read from the socket more than requested. This prevents stallin…
ionelmc commentedon Feb 8, 2014
I would appear that librabbitmq has the same stalling issue but looks harder to fix as it just reads up to the buffer's size, see https://github.com/ask/rabbitmq-c/blob/bfbe693e88f8495073f43571904cdbb817dc50ae/librabbitmq/amqp_socket.c#L211
ionelmc commentedon Feb 8, 2014
@sabw8217 You can test this fix by using 'pyamqp://' broker protocol (in case you have librabbitmq installed). Don't forget to install the code from the 2 PRs mentioned above.
sabw8217 commentedon Mar 7, 2014
I think there is still an issue here - it looks to me like what it is happening is that this call in asynloop() on line 41 of celery/worker/loops.py can receive messages up to the entire prefetch count of the worker in addition to the basic_consume_ok.
consumer.consume()
And when that happens the messages end up in the method_queue in the amqp Channel. If the entire prefetch count has been received, RMQ won't send anything to us until a message gets acked, but because RMQ isn't sending anything the socket FD never becomes ready to read, and we never end up calling the task handler(which would call drain_events and kick us out of this bad state, where there are prefetch_count basic_deliver messages in the pyamqp's internal method queue). It looks to me like doing this will fix it, but I'm guessing there should be a timeout on this call, and possibly this whole issue should be being addressed at a lower level:
ionelmc commentedon Mar 7, 2014
@sabw8217 are you still having the issue or is this a different problem ?
21 remaining items
thedrow commentedon Jul 8, 2015
@Rigdon feel free to contribute. We need pull requests fixing bugs like these.
explicitly drain events when gossip/heartbeat will not - fix for #1847
explicitly drain events when gossip/heartbeat will not - fix for #1847
ask commentedon Sep 25, 2015
Closed by #2823 Thanks everyone :)
Fix for #1847 cannot drain events for Redis. Closes #2827
tumb1er commentedon Oct 5, 2015
Applying patch to 3.1.18 doesn't work for me:
celery runs with keys:
explicitly drain events when gossip/heartbeat will not - fix for cele…
Fix for celery#1847 cannot drain events for Redis. Closes celery#2827
Cherry-pick ba75fa0 for celery#1847 and celery#2827
explicitly drain events when gossip/heartbeat will not - fix for cele…
Released Celery version 3.1.27+eventbrite
Released Celery version 3.1.27+eventbrite (#6)