WorkerLostError: Worker exited prematurely: exitcode 155
I have a host with a local-only (everything on the same host) Celery setup for some continuous data processing. Recently the load got much higher, all the CPU cores often are under 100% load and I've started to get WorkerLostError: Worker exited prematurely: exitcode 155 out of the blue multiple times per day. A worker works and then suddenly
ERROR/MainProcess] Task some_task[some_id] raised unexpected: WorkerLostError('Worker exited prematurely: exitcode 155.',)
Traceback (most recent call last):
File "...venv/local/lib/python2.7/site-packages/billiard/pool.py", line 1175, in mark_as_worker_lost
human_status(exitcode)),
WorkerLostError: Worker exited prematurely: exitcode 155.
I had Celery 3.1.19 but upgrading to the latest version changed nothing. Right now the versions are:
celery==3.1.20
amqp==1.4.9
billiard==3.3.0.22
kombu==3.0.33
I use Redis as the broker (tuned to save each message on the disk), and maybe these Celery settings will tell you something:
CELERY_ACKS_LATE = True
CELERYD_MAX_TASKS_PER_CHILD = 1
CELERYD_PREFETCH_MULTIPLIER = 1
#-Ofair
#CELERYD_CONCURRENCY is > 1
BROKER_CONNECTION_TIMEOUT = 4
BROKER_CONNECTION_MAX_RETRIES = 3
BROKER_TRANSPORT_OPTIONS = {
'fanout_prefix': True,
'fanout_patterns': True,
'visibility_timeout': CELERYD_TASK_TIME_LIMIT,
}
Also it is sometimes accompanied by:
Substantial drift from celery@social may mean clocks are out of sync. Current drift is 27 seconds. [orig: 2016-03-02 20:14:21.140773 recv: 2016-03-02 20:13:54.031917]
(ntp is installed long ago and ntpdate -q pool.ntp.org shows e.g. offset 0.019895 sec)
and
Timed out waiting for UP message from <Worker(Worker-383, started daemon)>
(if I understand correctly, this one is ok during heavy load but just FYI)
I have a similiar situation with the same configuration the error of the worker is:
ERROR/MainProcess] Task some_task[some_id] raised unexpected: WorkerLostError('Worker exited prematurely: exitcode 1.',) Traceback (most recent call last): File "...venv/local/lib/python2.7/site-packages/billiard/pool.py", line 1175, in mark_as_worker_lost human_status(exitcode)), WorkerLostError: Worker exited prematurely: exitcode 1.
I have the follow libraries:
celery==3.1.23 librabbitmq==1.61 billiard==3.3.0.23 kombu==3.0.35
In the log of celery I have these errors:
[ERROR/MainProcess] Timed out waiting for UP message from <Worker(Worker-91, started daemon)> [ERROR/MainProcess] Timed out waiting for UP message from <Worker(Worker-92, started daemon)> [ERROR/MainProcess] Timed out waiting for UP message from <Worker(Worker-93, started daemon)> [ERROR/MainProcess] Timed out waiting for UP message from <Worker(Worker-94, started daemon)> [ERROR/MainProcess] Process 'Worker-94' pid:50823 exited with 'signal 9 (SIGKILL)' [ERROR/MainProcess] Process 'Worker-93' pid:50822 exited with 'signal 9 (SIGKILL)' [ERROR/MainProcess] Process 'Worker-92' pid:50821 exited with 'signal 9 (SIGKILL)' [ERROR/MainProcess] Process 'Worker-91' pid:50820 exited with 'signal 9 (SIGKILL)'
This error started to happen since we updated to the last version of celery from 3.1.16 to 3.1.23. Note that there are no changes in our infrastructure and in our application that is same except the upgrade of celery, so from my point of views it could be something new introduced in the last version, but looking around I wasn't able to find further informations.
Since you have a very low value for maxtasksperchild, did you also enable the -Ofair worker argument?
Yes.
Also one more observation: the described situation probably correlates with the periods when redis saves its state to the RDB file. We are using the same redis for other data and this data has grown enough to be an issue - our RDB saving often quite paralyzes most of the host activity during. When I tried to turn it off and to leave only AOF persistance, I recall that "exitcode 155" events occured much less frequently (maybe stopped to occur at all - I don't remember this detail unfortunately and currently have not enough time to try it again). So - maybe it is caused by some kind of internal timeout in some part of the code which is expected not to deal with significant delays most of the time... Just a hypothesis.
I'm currently on 4.0 and using redis as broker as well. We have 180+ workers across 10 machines. We also use the same redis for multiple things. Interestingly sometimes I get 155, sometimes 0 as the exit code.
Apparently the error is "AttributeError: 'NoneType' object has no attribute 'can_read'" which I also reported and ask fixed in celery/kombu#659
I am too getting this error
[2017-01-01 16:49:02,922: ERROR/MainProcess] Task giraffe.tasks.tasks.execute_task[134803fb-1bc5-4167-aed9-3c241385a23b] raised unexpected: WorkerLostError('Worker exited prematurely: exitcode 155.',)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/billiard/pool.py", line 1175, in mark_as_worker_lost
human_status(exitcode)),
WorkerLostError: Worker exited prematurely: exitcode 155.
While searching on google for this error, I came to know that Exit code 155 is indeed that the process has been killed by SIGPROF signal, but I really don't understand it. Can anyone elaborate the reason for this error or ways to debug it ?
Getting this error as well, since we rely on after_return to publish something to redis, will be great at least the worker can call this function or other error handling function while encounter this
Getting this error with celery Version 4.0.2
error log as follow:
[2017-06-09 16:20:00.942315] [ljeugk] [c2] [2017-06-09 08:20:00,941: ERROR/MainProcess] Process 'PoolWorker-3' pid:19 exited with 'signal 9 (SIGKILL)'
[2017-06-09 16:20:00.954033] [ljeugk] [c2] [2017-06-09 08:20:00,953: ERROR/MainProcess] Task handler raised error: WorkerLostError('Worker exited prematurely: signal 9 (SIGKILL).',)
[2017-06-09 16:20:00.954078] [ljeugk] [c2] Traceback (most recent call last):
[2017-06-09 16:20:00.954094] [ljeugk] [c2] File "/usr/lib/python3.6/site-packages/billiard/pool.py", line 1224, in mark_as_worker_lost
[2017-06-09 16:20:00.954121] [ljeugk] [c2] human_status(exitcode)),
[2017-06-09 16:20:00.954136] [ljeugk] [c2] billiard.exceptions.WorkerLostError: Worker exited prematurely: signal 9 (SIGKILL).
Same issue, version 4.0.2.
2017-07-06 12:13:37,999: ERROR/MainProcess] Process 'PoolWorker-3' pid:22 exited with 'exitcode 2'
2017-07-06 12:13:38,019: ERROR/MainProcess] Task handler raised error: WorkerLostError('Worker exited prematurely: exitcode 2.',)
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/billiard/pool.py", line 1224, in mark_as_worker_lost
human_status(exitcode)),
billiard.exceptions.WorkerLostError: Worker exited prematurely: exitcode 2.
Caused by AttributeError being thrown from within py.test
INTERNALERROR> AttributeError: 'Config' object has no attribute '_html'
Causes a headache because the actual error is obscured.
You may check this.
$ ps auxw | grep 'celery -A project.celery.app' | wc -l
Is count of woker processes almost same as concurrency setting? Duplicated worker parent processes (which has same worker name) may cause EX_RECYCLE (exit code 155) error. If processes forked more than concurrency setting, stop worker and kill unintended process, then start worker again. After that, enqueue 100s of debug_task:
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
(http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html)
and check results (worker lost errors are still caused or not).
I've also encountered this issue.
software -> celery:4.1.0 (latentcall) kombu:4.1.0 py:2.7.11
billiard:3.5.0.3 librabbitmq:1.6.1
platform -> system:Darwin arch:64bit imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:librabbitmq results:redis://localhost:6379/0
CELERYD_MAX_TASKS_PER_CHILD = 1
Concurrency set to auto. Issue observed regardless of no of cores (4 or 32).
@ask, After some debugging and stepping through the source code of celery and deps, I'm starting to wonder if there is a race condition between maintaining worker pool and asynchronously setting job results through out queue.
What I'm observing is that the WorkerLostError exception is thrown momentarily, without waiting for the worker and before job results are pooled from out queue and before setting them on the ApplyResult object.
As you can see from the logs, job 44 get's ACKed, processed and the results are pushed back to the output queue. But before they're set on the ApplyResult object by the on_ready handler, the exception is thrown from the _join_exited_workers triggered by maintain_pool.
[ForkPoolWorker-41/log:235] ('Job ACKed, pushing to queue.', 0, 42, None, 176849.817321023, 25786, None)
[ForkPoolWorker-42/log:235] ('Job ACKed, pushing to queue.', 0, 40, None, 176849.819612783, 25787, None)
[ForkPoolWorker-43/log:235] ('Job ACKed, pushing to queue.', 0, 41, None, 176849.819172865, 25788, None)
[MainProcess/request:297] Task accepted: pid:25786
[MainProcess/request:297] Task accepted: pid:25787
[MainProcess/request:297] Task accepted: pid:25788
[ForkPoolWorker-41/log:235] ('Job result is ready, pushing to queue.', 1, 42, None, (True, (0, u'0', 0.12914543400984257)), 21)
[ForkPoolWorker-41/log:235] ('Exiting worker with ', 155)
[MainProcess/log:235] ('Setting job params (ApplyResult._set) ', <%s: 42 ack:True ready:False>, (True, (0, u'0', 0.12914543400984257)))
[ForkPoolWorker-43/log:235] ('Job result is ready, pushing to queue.', 1, 41, None, (True, (0, u'0', 0.14665917900856584)), 12)
[ForkPoolWorker-43/log:235] ('Exiting worker with ', 155)
[ForkPoolWorker-42/log:235] ('Job result is ready, pushing to queue.', 1, 40, None, (True, (0, u'0', 0.15719593700487167)), 6)
[ForkPoolWorker-42/log:235] ('Exiting worker with ', 155)
[MainProcess/log:235] ('Setting job params (ApplyResult._set) ', <%s: 40 ack:True ready:False>, (True, (0, u'0', 0.15719593700487167)))
[MainProcess/log:235] ('Setting job params (ApplyResult._set) ', <%s: 41 ack:True ready:False>, (True, (0, u'0', 0.14665917900856584)))
[ForkPoolWorker-44/log:235] ('Job ACKed, pushing to queue.', 0, 44, None, 176850.380908394, 25789, None)
[MainProcess/request:297] Task accepted: pid:25789
[ForkPoolWorker-44/log:235] ('Job result is ready, pushing to queue.', 1, 44, None, (True, (0, u'0', 0.12314903500373475)), 16)
[ForkPoolWorker-44/log:235] ('Exiting worker with ', 155)
[MainProcess/log:235] ('Setting job params (ApplyResult._set) ', <%s: 44 ack:True ready:False>, (False, <ExceptionInfo: WorkerLostError('Worker exited prematurely: exitcode 155.',)>))
[ERROR: MainProcess/request:390] Task handler raised error: WorkerLostError('Worker exited prematurely: exitcode 155.',)
Traceback (most recent call last):
File "~/.pyenv/versions/portentio-2.7.11/lib/python2.7/site-packages/billiard/pool.py", line 1227, in mark_as_worker_lost
human_status(exitcode)),
WorkerLostError: Worker exited prematurely: exitcode 155.
When worker is started with concurrency set to 1, there are no WorkerLostError exception during task execution.
Also, worker-lost-wait doesn't seem to have an effect here because the time between pushing results to queue and throwing WorkerLostError is way under 10 seconds (default value).
What's interesting is that this issue, on a system with 32 workers and a very big number of continuously processed small tasks leads to some deadlocks or crashes of the main worker process. After some time, the number of spawned subprocesses is correct yet, workers are not processing any task and I have to restart the main everything.
I've been seeing this with Celery 4.1.0. I'll see the 155 exit code when using worker_max_tasks_per_child, and decreasing it increases the frequency. I've seen the 0 exit code when sending SIGTERM to a large worker set. I know with the 155 error code the on_error callbacks are getting called with a WorkerLostErrors errors, and I believe the corresponding chains were being called as well (note I'm expecting some due to segfaults in some library code I'm using).
I'm tempted to add some logging around around the billiard.pool:1135 (first for loop in _join_exited_workers) to see what values it's seeing.
Same happen with me celery 4.10.0 worker_max_tasks_per_child = 20
We are also observing this issue when workers recycle themselves. Setting worker_max_tasks_per_child = 1 (so that workers are constantly recycled) causes it to be reliably observed (although its still non-deterministic, happening perhaps 1-3% of the time (that's not been measured!))
software -> celery:4.1.0 (latentcall) kombu:4.1.0 py:2.7.13
billiard:3.5.0.3 py-amqp:2.2.1
loader -> celery.loaders.app.AppLoader
settings -> transport:pyamqp results:rpc:///
(observed when using both rpc and redis backends)
so how to fix this question?
don't set worker_max_tasks_per_child maybe are a good idea
I've stopped setting any automated worker termination items (both max_tasks and max_mem as well). You can detect some of these based off of the error code, but I need to do more testing to verify that in all cases an exit code of 0 or 155 means the tasks actually finish.
I also have more playing around to do with smaller worker sets (e.g. rather than 4 workers with 40 processes each do 8 workers with 20 processes each) to see if that helps. I've also started removing all queues being watched and waiting for all tasks to finish prior to stopping/restarting the workers.
Can someone from the maintainers update us on this issue? We've started experiencing this about a month ago out of the blue.
Traceback (most recent call last): File "/var/www/octopus/octo/lib/python3.4/site-packages/billiard/pool.py", line 1223, in mark_as_worker_lost human_status(exitcode)), billiard.exceptions.WorkerLostError: Worker exited prematurely: signal 11 (SIGSEGV).
Same here, I just wanted to use Threading inside the task.
@jsynowiec do you have any fix in mind? or any suggested overhaul? feel free to send a PR.