You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "jostheim (via GitHub)" <gi...@apache.org> on 2025/07/18 03:57:57 UTC

[D] Airflow 3.0.3 task hangs at 100% on cpu forever [airflow]

GitHub user jostheim created a discussion: Airflow 3.0.3 task hangs at 100% on cpu forever

I have the following code:

```
@task(max_active_tis_per_dag=20) # type: ignore
    def parse_batch(batch, batch_idx):
        from pipelines.edgar.company_facts.gather.core import parse_company_facts_batch
        context = get_current_context()
        execution_date = context['ds'] if 'ds' in context else datetime.now(timezone.utc).strftime("%Y-%m-%d")
        docs = parse_company_facts_batch(batch)
        if docs:
            logger.info(f"Making df for {len(docs)} documents for batch {batch_idx} on execution_date={execution_date}")
            df = pd.DataFrame(docs)
            logger.info(f"df created with shape: {df.shape}")
            if 'val' in df.columns:
                df['val'] = df['val'].apply(lambda x: str(x) if x is not None else None)
            batch_dir = PARQUET_DIR / f"date={execution_date}"
            batch_dir.mkdir(parents=True, exist_ok=True)
            batch_file = batch_dir / f"batch_{batch_idx}.parquet"
            logger.info(f"Storing batch {batch_idx} to {batch_file}")
            df.to_parquet(batch_file, index=False, engine='fastparquet')
            logger.info(f"✅ Stored {len(df)} docs to {batch_file}")
        else:
            logger.info(f"⚠️ No docs to store for batch {batch_idx}")
```
this task is expanded into processing 188 batches, all finish but 1.  The one that doesn't finish writes the following final log lines:

```
[2025-07-17, 23:23:14] INFO - Making df for 1366501 documents for batch 6 on execution_date=2025-07-17: source="unusual_prefix_5e0a781c0f686a4f5e36dc5088121114c49b96b8_dag_gather_edgar_company_facts"
[2025-07-17, 23:23:19] INFO - df created with shape: (1366501, 14): source="unusual_prefix_5e0a781c0f686a4f5e36dc5088121114c49b96b8_dag_gather_edgar_company_facts"
[2025-07-17, 23:23:19] INFO - Storing batch 6 to /slow_data/stock_market/data/parquet/sec/company_facts/date=2025-07-17/batch_6.parquet: source="unusual_prefix_5e0a781c0f686a4f5e36dc5088121114c49b96b8_dag_gather_edgar_company_facts"
[2025-07-17, 23:23:23] INFO - ✅ Stored 1366501 docs to /slow_data/stock_market/data/parquet/sec/company_facts/date=2025-07-17/batch_6.parquet: 
```

as we can see from the code the last line of the task is the last line logged, but the task has not succeeded.  In fact the pid is running at 100% on one of my cores.  To see what it is doing I used py-spy
```
GIL: 100.00%, Active: 100.00%, Threads: 1

  %Own   %Total  OwnTime  TotalTime  Function (filename)
100.00% 100.00%   100.0s    100.0s   run (airflow/sdk/execution_time/callback_runner.py)
  0.00% 100.00%   0.000s    100.0s   _run_worker (airflow/executors/local_executor.py)
  0.00% 100.00%   0.000s    100.0s   supervise (airflow/sdk/execution_time/supervisor.py)
  0.00% 100.00%   0.000s    100.0s   _main (multiprocessing/spawn.py)
  0.00% 100.00%   0.000s    100.0s   <module> (<string>)
  0.00% 100.00%   0.000s    100.0s   _fork_main (airflow/sdk/execution_time/supervisor.py)
  0.00% 100.00%   0.000s    100.0s   _subprocess_main (airflow/sdk/execution_time/supervisor.py)
  0.00% 100.00%   0.000s    100.0s   run (airflow/sdk/execution_time/task_runner.py)
  0.00% 100.00%   0.000s    100.0s   execute_callable (standard/operators/python.py)
  0.00% 100.00%   0.000s    100.0s   main (airflow/sdk/execution_time/task_runner.py)
  0.00% 100.00%   0.000s    100.0s   start (airflow/sdk/execution_time/supervisor.py)
  0.00% 100.00%   0.000s    100.0s   _execute_work (airflow/executors/local_executor.py)
  0.00% 100.00%   0.000s    100.0s   _bootstrap (multiprocessing/process.py)
  0.00% 100.00%   0.000s    100.0s   _execute_task (airflow/sdk/execution_time/task_runner.py)
  0.00% 100.00%   0.000s    100.0s   wrapper (airflow/sdk/bases/operator.py)
  0.00% 100.00%   0.000s    100.0s   execute (standard/operators/python.py)
  0.00% 100.00%   0.000s    100.0s   spawn_main (multiprocessing/spawn.py)
  0.00% 100.00%   0.000s    100.0s   execute (airflow/sdk/bases/decorator.py)
  0.00% 100.00%   0.000s    100.0s   run (multiprocessing/process.py)
```

So it is sitting in run at 100% doing nothing, not succeeding and not allowing anything to proceed.  Given this is not in my code and the logging shows my code finished, I figured this has to be an issue of some sort.  To note I have set my:

```
Environment=AIRFLOW__CORE__MP_START_METHOD=spawn
```

to gain more isolation than fork as I was getting seg_faults and strange errors with pyarrow, pandas etc.  I have been able to repeat this failure mode twice, I have had other tasks also get hung up, but when I clear them they succeed, if someone wants me to add logging or whatever to see better what is happening I am happy to see if this will repeat.

GitHub link: https://github.com/apache/airflow/discussions/53482

----
This is an automatically sent email for commits@airflow.apache.org.
To unsubscribe, please send an email to: commits-unsubscribe@airflow.apache.org