antonysouthworth-halter opened a new pull request, #43063:
URL: https://github.com/apache/airflow/pull/43063

   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   closes: #42991 (discussion)
   
   <!-- Please keep an empty line above the dashes. -->
   
   In the course of investigating 
https://github.com/apache/airflow/discussions/42991 I am a bit suspicious that 
there is a race condition between the DB fetch on line 285 and the executor 
state check on line 312.
   
   Basically my suspicion is that the following order of operations is 
sometimes happening:
   
   - (backfill_job_runner.py) TI returned from the DB contains the old state 
(queued)
   - (celery worker) Worker dequeue the task and change state to running.
   - (celery worker) Worker complete the task and change state to success.
   - (backfill_job_runner.py) Executor state changes to success (celery async 
future thing)
   - (backfill_job_runner.py) Fail state comparison ("The executor reported 
that the task instance finished with state success, but the task instance's 
state attribute is queued.")
   
   More details on my situation in the above linked discussion, but important 
to know is in my case the worker is completing the task in about 300 
milliseconds.
   
   Therefore, I propose that the backfill job should "double-check" the task 
instance state if it is different from executor state by refreshing from DB. If 
the state is still different then fall back to the old logic of assuming that 
the task state has changed externally.
   
   I am not sure if I've picked the right base for this PR. The backfill stuff 
is being totally re-written for Airflow 3 as part of 
[AIP-78](https://cwiki.apache.org/confluence/display/AIRFLOW/AIP-78+Scheduler-managed+backfill)
 so I wouldn't know where to make this change or even if the same bug exists 
there.
   
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party 
License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a 
newsfragment file, named `{pr_number}.significant.rst` or 
`{issue_number}.significant.rst`, in 
[newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to