Skip to content

Using --celery-hostname causes workers to reserve, but never execute tasks #59707

Closed

Description

@CreeperBeatz

Apache Airflow Provider(s)

celery

Versions of Apache Airflow Providers

3.14.1

Apache Airflow version

3.1.5

Operating System

WSL Ubuntu 22.04

Deployment

Virtualenv installation

Deployment details

Installed with UV:

uv pip install "apache-airflow[celery]==3.1.5" --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-3.1.5/constraints-3.12.txt"

What happened

When starting a Celery worker with a custom --celery-hostname, the worker successfully connects to the broker and reserves tasks, but never executes them.

The task stays in reserved state with:

acknowledged: False
worker_pid: None
time_start: None

Removing --celery-hostname and using the default hostname makes everything work correctly.

Output when using --celery-hostname:

(.venv) me@DESKTOP-MAG5124:~/airflow$ celery -A airflow.providers.celery.executors.celery_executor_utils.app inspect reserved
->  default@DESKTOP-MAG5124: OK
    * {'id': '923f016a-a3da-42c2-bf57-4f4193e11721', 'name': 'execute_workload', 'args': ['{"token":"token_here","task_id":"get_airflow_variables","dag_id":"dirbg_crawler","run_id":"manual__2025-12-22T07:57:45+00:00","try_number":2,"map_index":-1,"pool_slots":1,"queue":"default","priority_weight":2,"parent_context_carrier":{},"context_carrier":{}},"dag_rel_path":"dirbg_crawler.py","bundle_info":{"name":"dags-folder","version":null},"log_path":"dag_id=dirbg_crawler/run_id=manual__2025-12-22T07:57:45+00:00/task_id=get_airflow_variables/attempt=2.log","type":"ExecuteTask"}'], 'kwargs': {}, 'type': 'execute_workload', 'hostname': 'default@DESKTOP-MAG5124', 'time_start': None, 'acknowledged': False, 'delivery_info': {'exchange': '', 'routing_key': 'default', 'priority': 0, 'redelivered': False}, 'worker_pid': None}

1 node online.
(.venv) me@DESKTOP-MAG5124:~/airflow$ celery -A airflow.providers.celery.executors.celery_executor_utils.app inspect active_queues
->  default@DESKTOP-MAG5124: OK
    * {'name': 'default', 'exchange': {'name': 'default', 'type': 'direct', 'arguments': None, 'durable': True, 'passive': False, 'auto_delete': False, 'delivery_mode': None, 'no_declare': False}, 'routing_key': 'default', 'queue_arguments': None, 'binding_arguments': None, 'consumer_arguments': None, 'durable': True, 'exclusive': False, 'auto_delete': False, 'no_ack': False, 'alias': None, 'bindings': [], 'no_declare': None, 'expires': None, 'message_ttl': None, 'max_length': None, 'max_length_bytes': None, 'max_priority': None}

1 node online.

Output when NOT using --celery-hostname:

Note: The task is already executing.

(.venv) dani@DESKTOP-MAG5124:~/airflow$ celery -A airflow.providers.celery.executors.celery_executor_utils.app inspect reserved
->  celery@DESKTOP-MAG5124: OK
    - empty -

What you think should happen instead

Worker should execute reserved tasks regardless of custom hostname.

How to reproduce

This does NOT work - task reserved but never executed

airflow celery worker \
  --queues my_queue \
  --concurrency 1 \
  --celery-hostname "myworker@%h"

This is valid even if you set the --celery-hostname to "celery@%h" which should be the default option.

This WORKS

airflow celery worker \
  --queues my_queue \
  --concurrency 1

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Dec 22, 2025
  2. CreeperBeatz commented on Dec 22, 2025

    @CreeperBeatz
    Author

    I just tested downgrading to Celery Providers 3.13.1, and the issue DOES NOT exist there. This is something that happened in the 3.14.* release of the celery providers.

  3. brunocmacedo commented on Dec 23, 2025

    @brunocmacedo
    Contributor

    After a couple hours trying to find what was the issue after 3.1.5 upgrade I found this and can confirm that I have the same issue with apache-airflow-providers-celery 3.14.1. Falling back to 3.13.1 solved the issue for now.

    As a reference, here is the airflow-worker definition in my docker compose. In my case i need to set celery-hostname due to the three replicas being used.

    airflow-worker:
            <<: *airflow-common
            command: celery worker --celery-hostname=%h
            healthcheck:
                test:
                    - "CMD-SHELL"
                    - 'celery --app airflow.providers.celery.executors.celery_executor.app inspect ping -d "celery@$${HOSTNAME}" || celery --app airflow.executors.celery_executor.app inspect ping -d "celery@$${HOSTNAME}"'
                interval: 30s
                timeout: 10s
                retries: 5
                start_period: 30s
            environment:
                <<: *airflow-common-env
                # Required to handle warm shutdown of the celery workers properly
                # See https://airflow.apache.org/docs/docker-stack/entrypoint.html#signal-propagation
                DUMB_INIT_SETSID: "0"
            restart: always
            depends_on:
                <<: *airflow-common-depends-on
                airflow-apiserver:
                    condition: service_healthy
                airflow-init:
                    condition: service_completed_successfully
            deploy:
                replicas: 3 # Number of worker replicas to run, increase this to create multiple worker containers allowing more parallel task execution
            mem_swappiness: 0 # Disable swap to prevent slowdowns
  4. sonbaoharryson commented on Jan 21, 2026

    @sonbaoharryson

    thanks @brunocmacedo , i did same things you provided, worked for me!!!

  5. mxmua commented on Feb 17, 2026

    @mxmua

    Same issue on v3.1.7 with apache-airflow-providers-celery 3.15.2.
    Works fine without --celery-hostname

  6. vikasgrover2 commented on Feb 26, 2026

    @vikasgrover2

    man the headache this caused. Not even ai could figure out what was going on until I stumbled into this thread.

  7. mszmidt commented on Mar 5, 2026

    @mszmidt

    Yeah, it was a huge pain... For us it started with 3.1.3 I believe. And took ~2 weeks to find this issue and alter config. (Self-built docker images installed with pipx) In the meantime we changed everything including Dockerfiles...

  8. added a commit that references this issue on Mar 10, 2026
    abbcd62
  9. shivaam commented on Mar 23, 2026

    @shivaam
    Contributor

    I did some testing and tried to replicate the issue on my end. I think commit 16829d7694 — "Add duplicate hostname check for Celery workers (#58591)" — landed in celery provider 3.14.0. This is the only CLI change between 3.13.1 and 3.14.0, consistent with reports that downgrading to 3.13.1 fixes the issue.

    Root Cause

    The duplicate hostname check calls celery_app.control.inspect().active_queues() before celery_app.worker_main(). The inspect() call opens broker connections and initializes internal connection/producer pools on the Celery app. When worker_main() starts the worker with the prefork pool (which uses fork()), this pre-initialized state interferes with the worker's internal communication — tasks are received from the broker but never dispatched to pool workers.

    I confirmed this by observing that app.amqp._producer_pool is non-None at worker_main() time when the bug occurs, and None when it works correctly. Clearing this state with kombu.pools.reset() after the inspect() call restores correct behavior.

    I have not fully traced the exact internal mechanism by which the pre-initialized pools break the prefork dispatch path, but the correlation is consistent across all tests.

    Fixes That Work (verified on live Airflow 3.2 + Celery 5.6.2 + Redis)

    Option A — Remove the duplicate hostname check entirely. Simplest fix, minor UX loss (no warning if you accidentally start two workers with the same hostname). Tested and confirmed working.

    Option B — Use a temp app + kombu.pools.reset(): Keeps the check, cleans up connection state before worker_main():

    if args.celery_hostname:
        from celery import Celery as _TempCelery
        temp_app = _TempCelery(broker=celery_app.conf.broker_url)
        try:
            active_workers = temp_app.control.inspect().active_queues()
            if active_workers:
                celery_hostname = args.celery_hostname
                if any(
                    name == celery_hostname or name.endswith(f"@{celery_hostname}")
                    for name in active_workers
                ):
                    raise SystemExit(
                        f"Error: A worker with hostname '{celery_hostname}' is already running."
                    )
        finally:
            temp_app.close()
            import kombu.pools
            kombu.pools.reset()

    The kombu.pools.reset() is essential — kombu.pools is a process-global registry keyed by broker URL, so even a separate temp app's connections end up in the same global pool.

    Approaches That Did Not Work

    Approach Result
    Reset app.amqp._producer_pool = None only Insufficient — kombu.pools still holds state
    Temp app without kombu.pools.reset() Global pools still polluted
    app.pool.force_close_all() Closes pool permanently, Celery can't reconnect

    Investigation branch with diagnostic scripts: investigate/celery-hostname-59707

  10. shivaam commented on Mar 23, 2026

    @shivaam
    Contributor

    @dheerajturaga Do you have any idea why the duplicate check might be causing this isuse? Is it fine if we remove the check?
    @hussein-awala wondering if you have any thoughts on this?

  11. shivaam commented on Apr 2, 2026

    @shivaam
    Contributor

    @auvipy wondering if you have any thoughts on this issue. Any inputs on what we can check further?

    The duplicate hostname check calls celery_app.control.inspect().active_queues() before celery_app.worker_main(). The inspect() call opens broker connections and initializes internal connection/producer pools on the Celery app. When worker_main() starts the worker with the prefork pool (which uses fork()), this pre-initialized state interferes with the worker's internal communication — tasks are received from the broker but never dispatched to pool workers.
    
    I confirmed this by observing that app.amqp._producer_pool is non-None at worker_main() time when the bug occurs, and None when it works correctly. Clearing this state with kombu.pools.reset() after the inspect() call restores correct behavior.
    
    I have not fully traced the exact internal mechanism by which the pre-initialized pools break the prefork dispatch path, but the correlation is consistent across all tests.
    
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

    area:corearea:providersgood first issuekind:bugneeds-triageprovider:celery

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions