Copilot commented on code in PR #64612:
URL: https://github.com/apache/airflow/pull/64612#discussion_r3025696212


##########
providers/apache/kafka/src/airflow/providers/apache/kafka/triggers/await_message.py:
##########
@@ -141,3 +142,7 @@ async def run(self):
                     if self.commit_offset:
                         await async_commit(message=message, asynchronous=False)
                     await asyncio.sleep(self.poll_interval)
+
+    async def cleanup(self) -> None:
+        if consumer := getattr(self, "_consumer", None):
+            consumer.close()

Review Comment:
   `cleanup()` calls `consumer.close()` directly inside the triggerer event 
loop. `confluent_kafka.Consumer.close()` can block (network I/O / group leave), 
which can stall the triggerer and delay other triggers. Consider running it via 
`sync_to_async`/`asyncio.to_thread` and making the cleanup best-effort (e.g., 
wrap in try/except and log) to align with BaseTrigger.cleanup semantics.



##########
providers/apache/kafka/src/airflow/providers/apache/kafka/triggers/await_message.py:
##########
@@ -108,6 +108,7 @@ async def run(self):
 
         async_get_consumer = sync_to_async(consumer_hook.get_consumer)
         consumer = await async_get_consumer()
+        self._consumer = consumer  # store for cleanup
 

Review Comment:
   `self._consumer` is introduced dynamically in `run()`. For clarity/type 
safety and to make cleanup idempotent, initialize `_consumer` (e.g., to `None`) 
in `__init__`, and in `cleanup()` set it back to `None` after closing so 
repeated cleanup calls don’t try to close the same consumer again.



-- 
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