Skip to content

Celery worker enters a catatonic state after redis restart #26542

Closed

Description

@wolfier

Apache Airflow version

main (development)

What happened

Worker seems to be stuck in a catatonic state where queued tasks instance messages are not consumed from redis.

Redis did restart while the worker remained as is. The worker did output logs that indicated a loss in connection but was able to reconnect after redis came back online.

[2022-09-19 23:58:00,794: ERROR/MainProcess] consumer: Cannot connect to redis://:**@accurate-axis-9558-redis:6379/0: Error 111 connecting to accurate-axis-9558-redis:6379. Connection refused..
Trying again in 2.00 seconds... (1/100)

[2022-09-19 23:58:03,802: ERROR/MainProcess] consumer: Cannot connect to redis://:**@accurate-axis-9558-redis:6379/0: Error 111 connecting to accurate-axis-9558-redis:6379. Connection refused..
Trying again in 4.00 seconds... (2/100)

[2022-09-19 23:58:08,830: ERROR/MainProcess] consumer: Cannot connect to redis://:**@accurate-axis-9558-redis:6379/0: Error 111 connecting to accurate-axis-9558-redis:6379. Connection refused..
Trying again in 6.00 seconds... (3/100)

[2022-09-19 23:58:15,866: ERROR/MainProcess] consumer: Cannot connect to redis://:**@accurate-axis-9558-redis:6379/0: Error 111 connecting to accurate-axis-9558-redis:6379. Connection refused..
Trying again in 8.00 seconds... (4/100)

[2022-09-19 23:58:24,890: ERROR/MainProcess] consumer: Cannot connect to redis://:**@accurate-axis-9558-redis:6379/0: Error 111 connecting to accurate-axis-9558-redis:6379. Connection refused..
Trying again in 10.00 seconds... (5/100)

[2022-09-19 23:58:34,907: INFO/MainProcess] Connected to redis://:**@accurate-axis-9558-redis:6379/0
[2022-09-19 23:58:34,915: INFO/MainProcess] mingle: searching for neighbors
[2022-09-19 23:58:35,923: INFO/MainProcess] mingle: all alone

What you think should happen instead

After redis comes back online and the worker connected again, the worker should consume the messages and execute queued task instances.

How to reproduce

  1. Delete the existing redis pod and the worker should be unable to connect to redis
  2. Redis restarts and the worker connects as expected
  3. Worker does not consume new messages (queued task instances)

Operating System

N/A

Versions of Apache Airflow Providers

No response

Deployment

Astronomer

Deployment details

No response

Anything else

There was a Github Discussion earlier this year about this behaviour.

This didn't seem to be an issue on an early version of celery (4.4.7).

The current installed version is celery==5.2.7 and I use redis versioned at 6.2.6.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    on Sep 21, 2022
  2. added
    _eol_affected_version:2.4
    priority:medium
    on Sep 21, 2022
  3. ashb commented on Sep 21, 2022

    @ashb
    Member

    Hmmm, this feels like a Celery issue, as all airflow celery worker does is run the celery app.

    (I'm not saying we shouldn't look at fixing it, just surprised that celery doesn't do it for us)

  4. wolfier commented on Sep 22, 2022

    @wolfier
    ContributorAuthor

    Yep! I linked the Github Discussion from celery Github.

    This is more just a record to keep track of this behaviour.

  5. wolfier commented on Oct 16, 2022

    @wolfier
    ContributorAuthor

    The new liveness probe on the Celery Worker (#25561) doesn't fix the root issue but does put in safeguards to reset the worker when workers become catatonic.

  6. Scorpion2115 commented on Sep 4, 2023

    @Scorpion2115

    I am having exactly the same issue with my Airflow 2.5.1

  7. potiuk commented on Sep 4, 2023

    @potiuk
    Member

    I am having exactly the same issue with my Airflow 2.5.1

    Are you using the official chart that has the safeguards as mentioned in ?

    The new liveness probe on the Celery Worker (#25561) doesn't fix the root issue but does put in safeguards to reset the worker when workers become catatonic.

  8. added and removed
    priority:medium
    _eol_affected_version:2.4
    on Sep 5, 2023
  9. Scorpion2115 commented on Sep 5, 2023

    @Scorpion2115

    I am having exactly the same issue with my Airflow 2.5.1

    Are you using the official chart that has the safeguards as mentioned in ?

    The new liveness probe on the Celery Worker (#25561) doesn't fix the root issue but does put in safeguards to reset the worker when workers become catatonic.

    Sorry my Airflow was deployed on normal EC2 instances, not Kubernetes.
    Is there any similar fix available?

  10. 9 remaining items

  11. potiuk commented on Jan 29, 2024

    @potiuk
    Member

    I'd wait with the doc changes to see if celery 5.4.0 solves this problem from the root then we can simply bump version

    I think it depends if those are "Generically applicable".

    I think a number of our users would still not use the latest celery, celery has quite a number of dependencies on it's own and it "adds" on top of the dependencies just plain airflow has. The problem with celery is that - similarly as in case of Airflow - the workers and dependencies of Celery share the same virtualenv that the task runs in, so there might be plenty of reasons why our users would like to use older celery version (in older Airflow) or maybe even downgrade celery version used even in future versions of Airlfow. Celery is pretty special because it generally impacts everyone running any task with any provider combinations, so I'd imagine it migh be much harder to expect people to upgrade it to 5.4.0.

    So I think if we ALSO have a way how to bring older celery configuration to "reasonable defaults", it's worth considering to explain that in the documentation and even our Helm Chart, and I am even happy to to it myself @dstandish @eladkal , but I need to know if those are defaults that are "ok" to be considered as sane defaults.

  12. potiuk commented on Jan 29, 2024

    @potiuk
    Member

    And just to add a bit more context to the discussion. It's a known fact that a number of our users have some troubles with stability running Celery-based deployment. I think if we know a way to make it more stable, keeping it as "secret-sauce" makes little sense. Also some people proposed other solutions to improve stability (which might or might not be related and they are way more invasive) and possibly the stability issues might be helped with better default configuration (in docs and in chart).

    I am particualarly referring to that one #31829 which proposes to disable the "ack late" feature to improve stability of Airflow Celery deployment, which comes from the creator of the "user community" chart. We - so far - generally ignored that one, mostly I guessm becasue we did not want to spend time on analysing all the consequences of disabling ack late.

    I personally have a feeling that it changes a lot of promises about delivery and taks handling in Celery, and shifts the problem to other set of edge cases, but maybe, by making the defaults working "better" out-of-the-box, the reason for the "ack late disabling" migh be generally gone as that might improve Celery deployment stability?

    That's just a thought and more context, the "ack late" ase bothers me for quite some time, but I do not have enough experience/knowledge in Celery to be able to provide more than just intuition, that maybe this one applied properly might solve problems that manifest in others trying other, worse effectively, things to improve the stability of celery.

  13. potiuk commented on Jan 29, 2024

    @potiuk
    Member

    And the new PR for "ack_late" - to complete the picture: #37066

  14. eladkal commented on Jan 30, 2024

    @eladkal
    Contributor

    So I think if we ALSO have a way how to bring older celery configuration to "reasonable defaults", it's worth considering to explain that in the documentation and even our Helm Chart, and I am even happy to to it myself @dstandish @eladkal , but I need to know if those are defaults that are "ok" to be considered as sane defaults.

    I am OK with it.
    If we don't know the values yet we can refer from the docs to this issue (or to github discussion) where we explain consideration and suggest a few options while letting the community to comment and participate in the discussion.

  15. alex-trm commented on Jan 21, 2025

    @alex-trm

    The discussion that @wolfier linked originally celery/celery#7276, has since been closed reporting that the issue is fixed in Celery >= 5.5.X. I'm going to test this and report back. People reported in the most recent comments of that discussion that upgrading has resolved this. Really hoping that this is the case!

    celery/kombu#2007

  16. potiuk commented on Jan 21, 2025

    @potiuk
    Member

    Please do !

  17. alex-trm commented on Jan 21, 2025

    @alex-trm

    I am able to reliably reproduce the issue using the official Helm chart. I haven't been able to do this before so I'd like to document the process here:

    • Scale down Redis statefulset to 0 replicas
    • Wait for worker to disconnect, and add about 10 seconds to that
    • Scale up Redis statefulset to 1 replica

    This seems to reliably disconnect the worker from Redis (expected, since the Redis pod is going down) and then reconnect the worker to Redis without the ability to run tasks. Shouldn't take 2-3 cycles of the above steps to trigger the catatonic state where the worker says that it's connected, isn't killed by the liveness probe, but can't accept tasks from the queue.


    I thought that it would be easier to just delete the Redis pod and have it restart without changing the number of replicas but that doesn't seem to do the trick. The kombu link I posted above mentions GC issues and I'm wondering if keeping Redis down for ~10 seconds is long enough for a few connection retries and maybe a GC loop but not so long that the liveness probe kills the worker. Regardless, these steps seem to reliably reproduce the issue.


    Next I will upgrade to celery==5.5.0rc4 and try that process again

  18. alex-trm commented on Jan 23, 2025

    @alex-trm

    I upgraded to celery==5.5.0rc4 and ran my reproduction scenario 3x. Every time the worker reconnected after Redis restarted it was able to start running tasks again. I actually think celery/kombu#2007 may have resolved the issue for Airflow Celery Executor using Redis as a queue!

    @potiuk What other testing do you think would be required for this? I'm going to upgrade our staging environment to this version and let it bake for a while.

  19. eladkal commented on Jan 23, 2025

    @eladkal
    Contributor

    Noting we have #43777 waiting for the 5.5.0 release

  20. alex-trm commented on Jan 23, 2025

    @alex-trm

    We're going to modify constraints to use rc4 for now to give it some time to test in staging / prod and I'll keep updating here with findings if we have any problems that continue after an upgrade w.r.t. this issue.

  21. alex-trm commented on Jan 23, 2025

    @alex-trm

    Would you rather have comments here or in PR?

  22. potiuk commented on Jan 25, 2025

    @potiuk
    Member

    Would you rather have comments here or in PR?

    Whatever. But best if you comment in Celery repo so that they finally release it if you confirm it fixes the issue :)

  23. alex-trm commented on Feb 21, 2025

    @alex-trm

    We were able to test and confirm that in production this resolved our catatonic worker issue. Looking forward to seeing the full release of 5.5 so we can get this into Airflow officially. @wolfier I think we may finally be done with the catatonic worker issue 💯

  24. eladkal commented on Feb 21, 2025

    @eladkal
    Contributor

    This up to Celery to release it. I suggest to check with them if they can expedite release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions