We have the first example of scheduler deadlock in the willd for MySQL for the new scheduler:

https://github.com/apache/airflow/pull/8550/checks?check_run_id=1258193958#step:6:1439

Would be great to track it down and fix before the prod release:

**NOTE**  For now the issue has been mitigated (according to the documentation of MySQL) by applying restarts (with exponential back-off) in #12046. This should help with beta-testing of Airlfow by the users and to see if the retries on deadlock has some potential negative effects (according to the documentation - they might have if they happen frequently enough). 

Some more analysis might be performed between now and 2.0.0 which might result in deciding that this issue does not need any more fixes than the current mitigation or some actual changes in the code that might result in preventing the deadlocks.


airflow/jobs/scheduler_job.py
num_queued_tis = self._do_scheduling(session)
                self.executor.heartbeat()
                session.expunge_all()
                num_finished_events = self._process_executor_events(session=session)
            self.processor_agent.heartbeat()
            
            self.heartbeat(only_if_necessary=True)
            self._emit_pool_metrics()
            loop_end_time = time.time()
            loop_duration = loop_end_time - loop_start_time
            self.log.debug("Ran scheduling loop in %.2f seconds", loop_duration)
            if not is_unit_test and not num_queued_tis and not num_finished_events:
                
                
                
                time.sleep(self._processor_poll_interval)
            if loop_count >= self.num_runs > 0:
                self.log.info(
                    "Exiting scheduler loop as requested number of runs (%d - got to %d) has been reached",
                    self.num_runs, loop_count,
                )
                break
            if self.processor_agent.done:
                self.log.info(
                    "Exiting scheduler loop as requested DAG parse count (%d) has been reached after %d "
                    " scheduler loops",
                    self.num_times_parse_dags, loop_count,
                )
                break
    def _do_scheduling(self, session) -> int: