try/except not working on WorkerLostError and signal 11

Open
#322 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Start with the WorkerLostError and SIGSEGV log shown in the issue, then trace how the bound task's try/except and task_failure.connect entry points are involved in worker-process termination. Compare the observed behavior with the project's worker-loss tests or documentation; done means establishing and testing a supported way to observe or log this failure, if one exists.

Written by the indexing model from the issue text.

Description

Hi,

Is there a way to catch the WorkerLostError exception when it does die from a SIGSEGV? It seems like this might be unavoidable in some cases because of OOM issues for certain CPU-intensive tasks. In which case I'd like to log it. But I can't seem to tap into the worker or celery life cycle to do this.

But I haven't been able to try/catch the exception so far, in either celery 4.4.0 or 5.0.0. I've tried modifying the task, and also task_failure.connect, but no luck.

logs:

[2020-10-14 19:23:22,154: ERROR/MainProcess] Process 'ForkPoolWorker-17' pid:48328 exited with 'signal 11 (SIGSEGV)'
[2020-10-14 19:23:22,170: ERROR/MainProcess] Task handler raised error: WorkerLostError('Worker exited prematurely: signal 11 (SIGSEGV).')
[2020-10-14 19:23:22,403: DEBUG/ForkPoolWorker-18] Using selector: KqueueSelector

the relevant celery code:

@app.task(bind=True, base=CalculationTask)
def async_calculate(self, id, **kwargs):
    serializer = get_serializer(id)
    try:
        return serializer.run()
    except Exception as e:
        print("ERROR")
        print(e)

...

@task_failure.connect
def task_fail_handler(sender, result, **kwargs):
    print("task_fail_handler ERROR")

Excuse the print statements :) but for whatever reason, I can't seem to capture this exception. Neither are getting triggered.

Dominant language
Python
Stars
436
Forks
273
Avg merge
4d 19h
Merged PRs (30d)
5

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from celery/billiard

All issues in celery/billiard

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.