Smid-IT opened a new issue, #77553:
URL: https://github.com/apache/airflow/issues/77553

   ### Under which category would you file this issue?
   
   Providers
   
   ### Apache Airflow version
   
   3.4.0
   
   ### What happened and how to reproduce it?
   
   **Issue Description**
   
   The triggerer froze completely and stayed frozen for a week until restarted 
manually. The supervisor detected it but did not recover:
   
   ```
   [error] TriggerRunner subprocess event loop appears deadlocked: no 
communication received for 30.8s (threshold: 30.0s). Skipping heartbeat so the 
triggerer appears unhealthy to the scheduler and its triggers are reassigned.
   ```
   
   Just before the freeze, one trigger fired and another restarted within one 
second. Five minutes later all Kafka consumers logged MAXPOLL ("Application 
maximum poll interval (300000ms) exceeded ... leaving group"), so nothing was 
polled after the freeze. The librdkafka client counter had reached 
`consumer-1340`, i.e. a new consumer per trigger run.
   
   While still frozen, I took stack dumps of the TriggerRunner subprocess 
(py-spy + gdb). The `sync_to_async` thread (ThreadPoolExecutor-0_0) holds the 
GIL and is stuck inside `Consumer.close()`, in the rebalance callback, waiting 
for librdkafka forever:
   
   ```
   Thread 23 (LWP 3297686):
   #3  pthread_cond_wait () from libc.so.6
   #5  rd_kafka_q_pop_serve0 () from librdkafka.so.1
   #6  rd_kafka_q_pop_serve () from librdkafka.so.1
   #7  rd_kafka_op_req () from librdkafka.so.1
   #8  rd_kafka_assign0 () from librdkafka.so.1
   #9  rd_kafka_assign () from librdkafka.so.1
   #10 Consumer_rebalance_cb () from confluent_kafka/cimpl.so
   #11 rd_kafka_poll_cb () from librdkafka.so.1
   #12 rd_kafka_consumer_close0 () from librdkafka.so.1
   #13 rd_kafka_consumer_close () from librdkafka.so.1
   #14 Consumer_close () from confluent_kafka/cimpl.so
   #17 PyObject_Vectorcall () from libpython3.13.so.1.0
   ```
   
   The main thread (event loop) is waiting for the GIL:
   
   ```
   Thread 1 (LWP 3297624):
   #3  pthread_cond_timedwait () from libc.so.6
   #5  PyEval_RestoreThread () from libpython3.13.so.1.0
   ```
   
   No librdkafka thread was waiting for the GIL, and no thread was in D state 
(no I/O hang). This matches the `cleanup()` added in #64612, which calls `await 
sync_to_async(consumer.close)()` on the shared sync_to_async thread.
   
   **Steps to reproduce**
   
   1. Create several DAGs with `AssetWatcher` + `KafkaMessageQueueTrigger`, all 
using the same Kafka connection (same `group.id`), each on its own topic (1 
partition).
   2. Produce messages frequently to at least two of the topics (in my case 
1000+ per week), so triggers fire and restart often.
   3. Within about a day the triggerer freezes as described above.
   
   Workaround: giving each trigger its own connection/`group.id` removes the 
cross-trigger rebalances. That makes the hang much rarer, but the underlying 
`close()` hang remains possible.
   
   ### What you think should happen instead?
   
   Closing a Kafka consumer should never be able to freeze the entire 
triggerer. Possible approaches: avoid creating/closing a consumer on every 
trigger run, unsubscribe and let the rebalance finish before close(), or run 
close() somewhere a hang cannot block the event loop. Also, when the supervisor 
detects a deadlocked TriggerRunner, it should restart it instead of only 
skipping heartbeats.
   
   ### Operating System
   
   Official Airflow Docker image (Python 3.13) on Ubuntu 24.04 host
   
   ### Deployment
   
   Docker-Compose
   
   ### Apache Airflow Provider(s)
   
   apache-kafka
   
   ### Versions of Apache Airflow Providers
   
   apache-airflow-providers-apache-kafka==3.0.0
   confluent-kafka==2.16.1 (bundled librdkafka 2.16.0)
   
   ### Official Helm Chart version
   
   Not Applicable
   
   ### Kubernetes Version
   
   _No response_
   
   ### Helm Chart configuration
   
   Not Applicable
   
   ### Docker Image customizations
   
   Extended official image with additional pip packages (custom LDAP auth 
manager). No changes to Kafka-related packages beyond the versions listed above.
   
   ### Anything else?
   
   Happened twice in about a week, only after adding busy Kafka-triggered DAGs. 
Deployment: CeleryExecutor, single triggerer, single-broker Kafka 3.9.0 
(KRaft). Full gdb and py-spy dumps are available on request.
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to