-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Fix Execution API state update conflicts in HA #59650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -384,6 +384,17 @@ def ti_update_state( | |
| ) | ||
|
|
||
| if previous_state != TaskInstanceState.RUNNING: | ||
| # In HA, it's possible to receive a "late" finish/state update after another | ||
| # component already moved the TI to a terminal state. Treat this as an idempotent no-op to avoid | ||
| # crashing the process. | ||
| if previous_state in set(TerminalTIState): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the |
||
| requested_state = getattr(ti_patch_payload.state, "value", ti_patch_payload.state) | ||
| log.info( | ||
| "Ignoring state update for already terminal task instance", | ||
| previous_state=previous_state, | ||
| requested_state=requested_state, | ||
| ) | ||
| return | ||
| log.warning( | ||
| "Cannot update Task Instance in invalid state", | ||
| previous_state=previous_state, | ||
|
|
||
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait -- how can this happen? If another component already moved to terminal state -- it means task was running in that other component/worker -- not the one that triggered this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 workers shouldn't be running the same task!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might happen in some edge cases of CeleryExecutor race conditions when celery thinks that task has not completed and cancels it (but it finishes between it gets cancelled) and sends the task and it gets picked by another worker.
Possibly there are similar edge cases in K8S executor. I think It would be great to describe the semantics of task execution for both - > at most once (which we don't have), at least once (which I think we have), exactly-once (which I think is not really achievable easily - without adding a lot of complexity).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, but it's happening in the K-Executor :/ #57618 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to verify this more but here's what I thought was going on:
Scheduler A tried to start X but the scheduler was marked failed. Scheduler B picked up the task(couldn't adopt) after resetting it and start X in another pod. At this point we now have two pods running. So I think one of the pods received an update state before the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have experienced the same state update issues with the CeleryExecutor, as well. It doesn't appear to be isolated to the k8s executor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdellarciprete That's a bug somewhere that needs fixing but the current fix here -- which this comment thread is for -- is too late. What needs to be fixed is workers not able to even run duplicate task -- not when task has run on both workers and both are trying to update it state.
This endpoint in this file is for the same.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it looks like the earlier PR fixed this issue and I wasn't testing on the right branch when I raised this. @pdellarciprete , can you confirm you are no longer seeing this issue after applying the previous fix(#59639)Oh, disregard this. I was testing with 1 scheduler