GitHub user dondaum created a discussion: Initializing the TriggerRunnerSupervisor client blocks the trigger event loop on the first trigger
While testing a new asynchronous notfier https://github.com/apache/airflow/pull/57541 I noticed a blocking trigger on the Triggerer that blocked for about 2 to 4 seconds. At first I thought it was a side effect of my new feature, but it's the same for all triggers. You will also receive some warnings about it (see below). This only happens the first time a trigger is run on the trigger. Next time everything will look good and there will be no warning. That made me curious. I traced it to the initialization of `TriggerRunnerSupervisor.client()` https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/jobs/triggerer_job_runner.py#L380 and the current implementation that handles requests coming in here https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/jobs/triggerer_job_runner.py#L388. The first request starts the client, which creates the `Client` and starts the `in_process_api_server()`, which calls `Cadwyn.__call__(),` etc. This is a blocking call. Is this behavior intentional? This could lead to confusion about poorly written triggers. ---------------------- Example logs _Frist trigger runs_ ```bash 2025-11-01T10:54:58.730933Z [info ] trigger ID 1 starting [airflow.jobs.triggerer_job_runner] loc=triggerer_job_runner.py:735 2025-11-01T10:54:58.731599Z [info ] Trigger fired event [airflow.jobs.triggerer_job_runner] loc=triggerer_job_runner.py:735 name='ID 1' result="TriggerEvent<{'state': <DeadlineCallbackState.RUNNING: 'running'>}>" 2025-11-01T10:54:58.848520Z [info ] Getting async client [task.stdout] 2025-11-01T10:54:58.851420Z [warning ] Executing <Task pending name='ID 1' coro=<TriggerRunner.run_trigger() running at /opt/airflow/airflow-core/src/airflow/jobs/triggerer_job_runner.py:1112> wait_for=<Future pending cb=[shield.<locals>._outer_done_callback() at /usr/python/lib /python3.10/asyncio/tasks.py:864, Task.task_wakeup()] created at /usr/python/lib/python3.10/asyncio/base_events.py:429> created at /usr/python/lib/python3.10/asyncio/tasks.py:337> took 0.119 seconds [asyncio] loc=triggerer_job_runner.py:735 2025-11-01T10:54:58.893524Z [warning ] 'HTTP_422_UNPROCESSABLE_ENTITY' is deprecated. Use 'HTTP_422_UNPROCESSABLE_CONTENT' instead. [py.warnings] category=DeprecationWarning filename=/opt/airflow/airflow-core/src/airflow/api_fastapi/execution_api/routes/__init__.py lineno=23 2025-11-01T10:55:01.564814Z [warning ] Executing <Task pending name='Task-3' coro=<Cadwyn.__call__() running at /usr/python/lib/python3.10/site-packages/cadwyn/applications.py:260> cb=[ASGIResponder.asgi_done_callback()] created at /usr/python/lib/python3.10/site-packages/a2wsgi /asgi.py:204> took 2.365 seconds [asyncio] loc=base_events.py:1904 2025-11-01T10:55:01.640508Z [debug ] Connection Retrieved 'slack_api_default' (via task-sdk) [airflow.sdk.bases.hook] loc=triggerer_job_runner.py:735 ``` _Second trigger runs_ ```bash 2025-11-01T11:11:27.159828Z [info ] trigger ID 1 starting [airflow.jobs.triggerer_job_runner] loc=triggerer_job_runner.py:735 2025-11-01T11:11:27.160391Z [info ] Trigger fired event [airflow.jobs.triggerer_job_runner] loc=triggerer_job_runner.py:735 name='ID 1' result="TriggerEvent<{'state': <DeadlineCallbackState.RUNNING: 'running'>}>" 2025-11-01T11:11:27.180343Z [info ] Getting async client [task.stdout] 2025-11-01T11:11:27.180543Z [debug ] Connection Retrieved 'slack_api_default' (via task-sdk) [airflow.sdk.bases.hook] loc=triggerer_job_runner.py:735 ``` GitHub link: https://github.com/apache/airflow/discussions/57672 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected]
