# Buggy code
async def check_random_tracker(self):
    """
    Calling this method will fetch a random tracker from the database, select some torrents that have this
    tracker, and perform a request to these trackers.
    """
    tracker_url = self.get_valid_next_tracker_for_auto_check()
    if tracker_url is None:
        self._logger.warning("No tracker to select from, skip")
        return

    self._logger.debug("Start selecting torrents on tracker %s.", tracker_url)

    # get the torrents that should be checked
    with db_session:
        tracker = self.tribler_session.mds.TrackerState.get(url=tracker_url)
        if not tracker:
            return
        dynamic_interval = TORRENT_CHECK_RETRY_INTERVAL * (2**tracker.failures)
        # FIXME: this is a really dumb fix for update_tracker_info not being called in some cases
        if tracker.failures >= MAX_TRACKER_FAILURES:
            tracker.alive = False
            return
        torrents = select(
            ts
            for ts in tracker.torrents
            if ts.last_check + dynamic_interval < int(time.time())
        )
        infohashes = [t.infohash for t in torrents[:MAX_TORRENTS_CHECKED_PER_SESSION]]

    if len(infohashes) == 0:
        # We have no torrent to recheck for this tracker. Still update the last_check for this tracker.
        self._logger.info("No torrent to check for tracker %s", tracker_url)
        self.update_tracker_info(tracker_url, True)
        return

    try:
        session = self._create_session_for_request(tracker_url, timeout=30)
    except MalformedTrackerURLException as e:
        # Remove the tracker from the database
        self.remove_tracker(tracker_url)
        self._logger.error(e)
        return

    # We shuffle the list so that different infohashes are checked on subsequent scrape requests if the total
    # number of infohashes exceeds the maximum number of infohashes we check.
    random.shuffle(infohashes)
    for infohash in infohashes:
        session.add_infohash(infohash)

    self._logger.info(
        "Selected %d new torrents to check on tracker: %s", len(infohashes), tracker_url
    )
    try:
        await self.connect_to_tracker(session)
    except:
        pass


# Traceback (RuntimeError)
Traceback (most recent call last):
File "src\tribler-gui\tribler_gui\event_request_manager.py", line 112, in on_read_data
RuntimeError: 'NoneType' object has no attribute 'get_next_tracker_for_auto_check'
--LONG TEXT--
Traceback (most recent call last):
File "lib\asyncio\events.py", line 88, in _run
File "ipv8\taskmanager.py", line 123, in done_cb
File "ipv8\taskmanager.py", line 17, in interval_runner
File "src\tribler-core\tribler_core\modules\torrent_checker\torrent_checker.py", line 90, in check_random_tracker
File "src\tribler-core\tribler_core\modules\torrent_checker\torrent_checker.py", line 177, in get_valid_next_tracker_for_auto_check
File "src\tribler-core\tribler_core\modules\torrent_checker\torrent_checker.py", line 184, in get_next_tracker_for_auto_check
AttributeError: 'NoneType' object has no attribute 'get_next_tracker_for_auto_check'
--CONTEXT--
{'message': 'Exception in callback TaskManager.register_task.<locals>.done_cb(<Task finishe...auto_check\'")>) at ipv8\\taskmanager.py:120', 'exception': AttributeError("'NoneType' object has no attribute 'get_next_tracker_for_auto_check'"), 'handle': <Handle TaskManager.register_task.<locals>.done_cb(<Task finishe...auto_check'")>) at ipv8\taskmanager.py:120>}

# Fixed code
async def check_random_tracker(self):
    """
    Calling this method will fetch a random tracker from the database, select some torrents that have this
    tracker, and perform a request to these trackers.
    Return whether the check was successful.
    """
    if self._should_stop:
        self._logger.warning("Not performing tracker check since we are shutting down")
        return False

    tracker = self.get_valid_next_tracker_for_auto_check()
    if tracker is None:
        self._logger.warning("No tracker to select from, skip")
        return False

    self._logger.debug("Start selecting torrents on tracker %s.", tracker.url)

    # get the torrents that should be checked
    with db_session:
        dynamic_interval = TORRENT_CHECK_RETRY_INTERVAL * (2**tracker.failures)
        # FIXME: this is a really dumb fix for update_tracker_info not being called in some cases
        if tracker.failures >= MAX_TRACKER_FAILURES:
            self.update_tracker_info(tracker.url, False)
            return False
        torrents = select(
            ts
            for ts in tracker.torrents
            if ts.last_check + dynamic_interval < int(time.time())
        )
        infohashes = [t.infohash for t in torrents[:MAX_TORRENTS_CHECKED_PER_SESSION]]

    if len(infohashes) == 0:
        # We have no torrent to recheck for this tracker. Still update the last_check for this tracker.
        self._logger.info("No torrent to check for tracker %s", tracker.url)
        self.update_tracker_info(tracker.url, True)
        return False

    try:
        session = self._create_session_for_request(tracker.url, timeout=30)
    except MalformedTrackerURLException as e:
        # Remove the tracker from the database
        self.remove_tracker(tracker.url)
        self._logger.error(e)
        return False

    # We shuffle the list so that different infohashes are checked on subsequent scrape requests if the total
    # number of infohashes exceeds the maximum number of infohashes we check.
    random.shuffle(infohashes)
    for infohash in infohashes:
        session.add_infohash(infohash)

    self._logger.info(
        "Selected %d new torrents to check on tracker: %s", len(infohashes), tracker.url
    )
    try:
        await self.connect_to_tracker(session)
        return True
    except:
        return False