# Buggy code
def start(self, core_args=None, core_env=None):
    """
    First test whether we already have a Tribler process listening on port 8085. If so, use that one and don't
    start a new, fresh session.
    """

    def on_request_error(_):
        self.use_existing_core = False
        self.start_tribler_core(core_args=core_args, core_env=core_env)

    self.events_manager.connect()
    connect(self.events_manager.reply.error, on_request_error)
    # This is a hack to determine if we have notify the user to wait for the directory fork to finish
    _, _, src_dir, tgt_dir = should_fork_state_directory(
        get_root_state_directory(), version_id
    )
    if src_dir is not None:
        # There is going to be a directory fork, so we extend the core connection timeout and notify the user
        self.events_manager.remaining_connection_attempts = 1200
        self.events_manager.change_loading_text.emit(
            "Copying data from previous Tribler version, please wait"
        )


# Traceback (tribler_gui.event_request_manager.CoreConnectTimeoutError)
Traceback (most recent call last):
File "src\tribler-gui\tribler_gui\event_request_manager.py", line 138, in <lambda>
File "src\tribler-gui\tribler_gui\event_request_manager.py", line 80, in on_error
tribler_gui.event_request_manager.CoreConnectTimeoutError: Could not connect with the Tribler Core within 60 seconds
[PID:5376] 2020-08-25 15:41:08,656 - ERROR <session:366> Session.unhandled_error_observer(): Unhandled exception occurred! [Errno 10048] error while attempting to bind on address ('127.0.0.1', 8085): une seule utilisation de chaque adresse de socket (protocole/adresse r�seau/port) est habituellement autoris�e
--LONG TEXT--
Traceback (most recent call last):
File "src\run_tribler.py", line 81, in start_tribler
File "src\tribler-core\tribler_core\session.py", line 397, in start
File "src\tribler-core\tribler_core\restapi\rest_manager.py", line 77, in start
File "lib\site-packages\aiohttp\web_runner.py", line 100, in start
File "lib\asyncio\base_events.py", line 1463, in create_server
OSError: [Errno 10048] error while attempting to bind on address ('127.0.0.1', 8085): une seule utilisation de chaque adresse de socket (protocole/adresse r�seau/port) est habituellement autoris�e

--CONTEXT--
{'message': 'Task exception was never retrieved', 'exception': OSError(10048, "error while attempting to bind on address ('127.0.0.1', 8085): une seule utilisation de chaque adresse de socket (protocole/adresse r�seau/port) est habituellement autoris�e"), 'future': <Task finished name='Task-1' coro=<start_tribler_core.<locals>.start_tribler() done, defined at src\run_tribler.py:50> exception=OSError(10048, "error while attempting to bind on address ('127.0.0.1', 8085): une seule utilisation de chaque adresse de socket (protocole/adresse r�seau/port) est habituellement autoris�e")>}

# Fixed code
def start(self, core_args=None, core_env=None):
    """
    First test whether we already have a Tribler process listening on port <CORE_API_PORT>.
    If so, use that one and don't start a new, fresh session.
    """

    def on_request_error(_):
        self.use_existing_core = False
        self.start_tribler_core(core_args=core_args, core_env=core_env)

    self.events_manager.connect()
    connect(self.events_manager.reply.error, on_request_error)
    # This is a hack to determine if we have notify the user to wait for the directory fork to finish
    _, _, src_dir, tgt_dir = should_fork_state_directory(
        get_root_state_directory(), version_id
    )
    if src_dir is not None:
        # There is going to be a directory fork, so we extend the core connection timeout and notify the user
        self.events_manager.remaining_connection_attempts = 1200
        self.events_manager.change_loading_text.emit(
            "Copying data from previous Tribler version, please wait"
        )