Occasional failures:

https://github.com/apache/airflow/pull/14531/checks?check_run_id=2106170532#step:6:10454

```
 ________________ TestSchedulerJob.test_retry_still_in_executor _________________
  
  self = <tests.jobs.test_scheduler_job.TestSchedulerJob testMethod=test_retry_still_in_executor>
  
      def test_retry_still_in_executor(self):
          """
          Checks if the scheduler does not put a task in limbo, when a task is retried
          but is still present in the executor.
          """
          executor = MockExecutor(do_update=False)
          dagbag = DagBag(dag_folder=os.path.join(settings.DAGS_FOLDER, "no_dags.py"), include_examples=False)
          dagbag.dags.clear()
      
          dag = DAG(dag_id='test_retry_still_in_executor', start_date=DEFAULT_DATE, schedule_interval="@once")
          dag_task1 = BashOperator(
              task_id='test_retry_handling_op', bash_command='exit 1', retries=1, dag=dag, owner='airflow'
          )
      
          dag.clear()
          dag.is_subdag = False
      
          with create_session() as session:
              orm_dag = DagModel(dag_id=dag.dag_id)
              orm_dag.is_paused = False
              session.merge(orm_dag)
      
          dagbag.bag_dag(dag=dag, root_dag=dag)
          dagbag.sync_to_db()
      
          @mock.patch('airflow.jobs.scheduler_job.DagBag', return_value=dagbag)
          def do_schedule(mock_dagbag):
              # Use a empty file since the above mock will return the
              # expected DAGs. Also specify only a single file so that it doesn't
              # try to schedule the above DAG repeatedly.
              scheduler = SchedulerJob(
                  num_runs=1, executor=executor, subdir=os.path.join(settings.DAGS_FOLDER, "no_dags.py")
              )
              scheduler.heartrate = 0
              scheduler.run()
      
          do_schedule()  # pylint: disable=no-value-for-parameter
          with create_session() as session:
              ti = (
                  session.query(TaskInstance)
                  .filter(
                      TaskInstance.dag_id == 'test_retry_still_in_executor',
                      TaskInstance.task_id == 'test_retry_handling_op',
                  )
                  .first()
              )
          ti.task = dag_task1
      
          def run_with_error(ti, ignore_ti_state=False):
              try:
                  ti.run(ignore_ti_state=ignore_ti_state)
              except AirflowException:
                  pass
      
          assert ti.try_number == 1
          # At this point, scheduler has tried to schedule the task once and
          # heartbeated the executor once, which moved the state of the task from
          # SCHEDULED to QUEUED and then to SCHEDULED, to fail the task execution
          # we need to ignore the TaskInstance state as SCHEDULED is not a valid state to start
          # executing task.
          run_with_error(ti, ignore_ti_state=True)
          assert ti.state == State.UP_FOR_RETRY
          assert ti.try_number == 2
      
          with create_session() as session:
              ti.refresh_from_db(lock_for_update=True, session=session)
              ti.state = State.SCHEDULED
              session.merge(ti)
      
          # To verify that task does get re-queued.
          executor.do_update = True
          do_schedule()  # pylint: disable=no-value-for-parameter
          ti.refresh_from_db()
  >       assert ti.state == State.SUCCESS
  E       AssertionError: assert None == 'success'
  E        +  where None = <TaskInstance: test_retry_still_in_executor.test_retry_handling_op 2016-01-01 00:00:00+00:00 [None]>.state
  E        +  and   'success' = State.SUCCESS
  
  tests/jobs/test_scheduler_job.py:2934: AssertionError
```

<!--

Welcome to Apache Airflow!  For a smooth issue process, try to answer the following questions.
Don't worry if they're not all applicable; just try to include what you can :-)

If you need to include code snippets or logs, please put them in fenced code
blocks.  If they're super-long, please use the details tag like
<details><summary>super-long log</summary> lots of stuff </details>

Please delete these comment blocks before submitting the issue.

-->

<!--

IMPORTANT!!!

PLEASE CHECK "SIMILAR TO X EXISTING ISSUES" OPTION IF VISIBLE
NEXT TO "SUBMIT NEW ISSUE" BUTTON!!!

PLEASE CHECK IF THIS ISSUE HAS BEEN REPORTED PREVIOUSLY USING SEARCH!!!

Please complete the next sections or the issue will be closed.
These questions are the first thing we need to know to understand the context.

-->

**Apache Airflow version**:


**Kubernetes version (if you are using kubernetes)** (use `kubectl version`):

**Environment**:

- **Cloud provider or hardware configuration**:
- **OS** (e.g. from /etc/os-release):
- **Kernel** (e.g. `uname -a`):
- **Install tools**:
- **Others**:

**What happened**:

<!-- (please include exact error messages if you can) -->

**What you expected to happen**:

<!-- What do you think went wrong? -->

**How to reproduce it**:
<!---

As minimally and precisely as possible. Keep in mind we do not have access to your cluster or dags.

If you are using kubernetes, please attempt to recreate the issue using minikube or kind.

## Install minikube/kind

- Minikube https://minikube.sigs.k8s.io/docs/start/
- Kind https://kind.sigs.k8s.io/docs/user/quick-start/

If this is a UI bug, please provide a screenshot of the bug or a link to a youtube video of the bug in action

You can include images using the .md style of
![alt text](http://url/to/img.png)

To record a screencast, mac users can use QuickTime and then create an unlisted youtube video with the resulting .mov file.

--->


**Anything else we need to know**:

<!--

How often does this problem occur? Once? Every time etc?

Any relevant logs to include? Put them here in side a detail tag:
<details><summary>x.log</summary> lots of stuff </details>

-->

tests/jobs/test_scheduler_job.py
dag_id = 'test_reset_orphaned_tasks_no_orphans'
        dag = DAG(dag_id=dag_id, start_date=DEFAULT_DATE, schedule_interval='@daily')
        task_id = dag_id + '_task'
        DummyOperator(task_id=task_id, dag=dag)
        scheduler = SchedulerJob(subdir=os.devnull)
        session = settings.Session()
        session.add(scheduler)
        session.flush()
        dr1 = dag.create_dagrun(
            run_type=DagRunType.SCHEDULED,
            state=State.RUNNING,
            execution_date=DEFAULT_DATE,
            start_date=DEFAULT_DATE,
            session=session,
        )
        tis = dr1.get_task_instances(session=session)
        tis[0].state = State.RUNNING
        tis[0].queued_by_job_id = scheduler.id
        session.merge(dr1)
        session.merge(tis[0])
        session.flush()
        assert 0 == scheduler.adopt_or_reset_orphaned_tasks(session=session)
        tis[0].refresh_from_db()
        assert State.RUNNING == tis[0].state
    def test_reset_orphaned_tasks_non_running_dagruns(self):