# Buggy code
async def get_events(self, request):
    """
    .. http:get:: /events

    A GET request to this endpoint will open the event connection.

        **Example request**:

            .. sourcecode:: none

                curl -X GET http://localhost:8085/events
    """

    # Setting content-type to text/event-stream to ensure browsers will handle the content properly
    response = RESTStreamResponse(
        status=200,
        reason="OK",
        headers={
            "Content-Type": "text/event-stream",
            "Cache-Control": "no-cache",
            "Connection": "keep-alive",
        },
    )
    await response.prepare(request)
    # FIXME: Proper start check!
    await response.write(
        b"data: "
        + json.dumps(
            {
                "type": NTFY.EVENTS_START.value,
                "event": {
                    "tribler_started": self.tribler_started,
                    "version": version_id,
                },
            }
        ).encode("utf-8")
        + b"\n\n"
    )
    self.events_responses.append(response)
    try:
        while True:
            await self.register_anonymous_task("event_sleep", lambda: None, delay=3600)
    except CancelledError:
        self.events_responses.remove(response)
        return response


# 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
async def get_events(self, request):
    """
    .. http:get:: /events

    A GET request to this endpoint will open the event connection.

        **Example request**:

            .. sourcecode:: none

                curl -X GET http://localhost:52194/events
    """

    # Setting content-type to text/event-stream to ensure browsers will handle the content properly
    response = RESTStreamResponse(
        status=200,
        reason="OK",
        headers={
            "Content-Type": "text/event-stream",
            "Cache-Control": "no-cache",
            "Connection": "keep-alive",
        },
    )
    await response.prepare(request)
    # FIXME: Proper start check!
    await response.write(
        b"data: "
        + json.dumps(
            {
                "type": NTFY.EVENTS_START.value,
                "event": {
                    "tribler_started": self.tribler_started,
                    "version": version_id,
                },
            }
        ).encode("utf-8")
        + b"\n\n"
    )
    self.events_responses.append(response)
    try:
        while True:
            await self.register_anonymous_task("event_sleep", lambda: None, delay=3600)
    except CancelledError:
        self.events_responses.remove(response)
        return response