Change Trigger<->Supervisor communication to avoid stalls#48880
Merged
Conversation
ashb
requested review from
amoghrajesh,
dstandish,
hussein-awala and
kaxil
as code owners
April 7, 2025 15:11
Member
Author
The TriggerRunnerSupervisor previoulsy sent messges to the Triggerer directly when a trigger needed to be created or cancelled, and this initially worked fine, but when we later added the ability for Triggers to access Connections and Variables this ended up causing problems. The issue was that we broke one of the "rules" of comms, which is even documents as such in `airflow/sdk/exeuction_time/comms.py`: > * No messages are sent to task process except in response to a request. > (This is because the task process will be running user's code, so we can't > read from stdin until we enter our code, such as when requesting an XCom ) value etc.) The net result of this was that since the supervisor sent messages un-solicited, if things were timed badly, then the trigger would send a request for a Conn, and the supervisor would reply with a trigger to create etc. This sort of instability was very likely the cause of our flakeyness in the `test_trigger_can_access_variables_connections_and_xcoms` test. This fixes things by making the TriggerRunnerSupervisor collect the triggers to create/cancel in a deqeue in memory, and respond to the TriggerStateChanges messages with TriggerStateSync with the info it would have sent on an as-needed basis. In order to make sure that we only send+receive one message at a time I have swapped from the `threading.lock` to `aiologic.Lock` which allows for better locking/waiting behaviour between threads (which is what Triggers will use via the `sync_to_async`) and the main TriggerRunner.
ashb
force-pushed
the
trigger-comms-paths
branch
from
April 7, 2025 15:44
38c3c69 to
398de36
Compare
kaxil
approved these changes
Apr 7, 2025
kaxil
reviewed
Apr 7, 2025
Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
kaxil
reviewed
Apr 7, 2025
Member
Author
|
Looks like this hasn't fixed the flakey test. Dang |
ashb
commented
Apr 7, 2025
Member
|
Nice thanks Ash, just verified it looks fine now. One thing the locks should be used in async context, so likely the xcom and variable methods updates required. |
1 task
Member
Author
aiologic has locks that are valid in sync and async context, so the existing lock that Connection etc takes works fine. |
simonprydden
pushed a commit
to simonprydden/airflow
that referenced
this pull request
Apr 8, 2025
The TriggerRunnerSupervisor previoulsy sent messges to the Triggerer directly when a trigger needed to be created or cancelled, and this initially worked fine, but when we later added the ability for Triggers to access Connections and Variables this ended up causing problems. The issue was that we broke one of the "rules" of comms, which is even documents as such in `airflow/sdk/exeuction_time/comms.py`: > * No messages are sent to task process except in response to a request. > (This is because the task process will be running user's code, so we can't > read from stdin until we enter our code, such as when requesting an XCom ) value etc.) The net result of this was that since the supervisor sent messages un-solicited, if things were timed badly, then the trigger would send a request for a Conn, and the supervisor would reply with a trigger to create etc. This sort of instability was very likely the cause of our flakeyness in the `test_trigger_can_access_variables_connections_and_xcoms` test. This fixes things by making the TriggerRunnerSupervisor collect the triggers to create/cancel in a deqeue in memory, and respond to the TriggerStateChanges messages with TriggerStateSync with the info it would have sent on an as-needed basis. In order to make sure that we only send+receive one message at a time I have swapped from the `threading.lock` to `aiologic.Lock` which allows for better locking/waiting behaviour between threads (which is what Triggers will use via the `sync_to_async`) and the main TriggerRunner. Fixes apache#48820
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The TriggerRunnerSupervisor previoulsy sent messges to the Triggerer directly
when a trigger needed to be created or cancelled, and this initially worked
fine, but when we later added the ability for Triggers to access Connections
and Variables this ended up causing problems.
The issue was that we broke one of the "rules" of comms, which is even
documented as such in
airflow/sdk/exeuction_time/comms.py:The net result of this was that since the supervisor sent messages
un-solicited, if things were timed badly, then the trigger would send a
request for a Conn, and the supervisor would reply with a trigger to create
etc.
This sort of instability was very likely the cause of our flakeyness in the
test_trigger_can_access_variables_connections_and_xcomstest.This fixes things by making the TriggerRunnerSupervisor collect the triggers
to create/cancel in a deqeue in memory, and respond to the TriggerStateChanges
messages with TriggerStateSync with the info it would have sent on an
as-needed basis.
In order to make sure that we only send+receive one message at a time I have
swapped from the
threading.locktoaiologic.Lockwhich allows for betterlocking/waiting behaviour between threads (which is what Triggers will use via
the
sync_to_async) and the main TriggerRunner.Fixes #48820 in a different manner.
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.