imLinguin / comet

Open Source implementation of GOG Galaxy Communication Service for SDK bundled with GOG games.
GNU General Public License v3.0
246 stars 10 forks source link

Error handling #3

Closed purplebar0 closed 7 months ago

purplebar0 commented 1 year ago

While testing, I found that two common scenarios print a traceback rather than a descriptive error message, and it results in Comet aborting operation, which is obviously not ideal for a daemon.

  1. notifications-pusher.gog.com and gameplay.gog.com are not reachable (no Internet connection, hosts blocked, etc.)
INFO:comet_main:started listening on port 9977
41173
Accepting connection
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/aiohttp/connector.py", line 980, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1085, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 674, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('0.0.0.0', 443)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/redacted/builds/comet/comet/main.py", line 86, in <module>
    asyncio.run(con_handler.handle_connection())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/redacted/builds/comet/comet/handlers.py", line 90, in handle_connection
    await self.notification_pusher.setup()
  File "/home/redacted/builds/comet/comet/api/notification_pusher.py", line 34, in setup
    self.connection = await self.session.ws_connect(self.url)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/aiohttp/client.py", line 779, in _ws_connect
    resp = await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/aiohttp/client.py", line 536, in _request
    conn = await self._connector.connect(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/aiohttp/connector.py", line 540, in connect
    proto = await self._create_connection(req, traces, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/aiohttp/connector.py", line 901, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "/usr/lib/python3.11/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/aiohttp/connector.py", line 988, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host notifications-pusher.gog.com:443 ssl:default [Connect call failed ('0.0.0.0', 443)]
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fdf9dddd850>
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fdf9dddd990>
  1. Outdated token values
INFO:comet_main:started listening on port 9977
38489
Accepting connection
INFO:handler:handle_message:Header 1|3
INFO:notification_pusher:handling_connection:started
INFO:notification_pusher:notification_message:2|2
INFO:notification_pusher:subscribing to chat, presence, friends
Error obtaining user data
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/redacted/builds/comet/comet/main.py", line 86, in <module>
    asyncio.run(con_handler.handle_connection())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/redacted/builds/comet/comet/handlers.py", line 131, in handle_connection
    await self.handle_message(header_size_bytes)
  File "/home/redacted/builds/comet/comet/handlers.py", line 162, in handle_message
    res = await self.handle_auth_request(message_data)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/redacted/builds/comet/comet/handlers.py", line 214, in handle_auth_request
    res_data.user_id = int(user_info["galaxyUserId"])
                           ~~~~~~~~~^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fe9a8f39a50>
ERROR:asyncio:Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7fe9a8f25630>, 12558.577621949)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x7fe9a8f25470>, 12558.622148064)]']
connector: <aiohttp.connector.TCPConnector object at 0x7fe9a8f39a90>
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fe9a94e24d0>
Exception ignored in: <function ClientResponse.__del__ at 0x7fe9a8fff420>
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 811, in __del__
  File "/usr/lib/python3.11/site-packages/aiohttp/connector.py", line 178, in release
  File "/usr/lib/python3.11/site-packages/aiohttp/connector.py", line 663, in _release
  File "/usr/lib/python3.11/site-packages/aiohttp/client_proto.py", line 63, in close
  File "/usr/lib/python3.11/asyncio/sslproto.py", line 112, in close
  File "/usr/lib/python3.11/asyncio/sslproto.py", line 619, in _start_shutdown
  File "/usr/lib/python3.11/asyncio/base_events.py", line 727, in call_later
  File "/usr/lib/python3.11/asyncio/base_events.py", line 740, in call_at
  File "/usr/lib/python3.11/asyncio/base_events.py", line 519, in _check_closed
RuntimeError: Event loop is closed
imLinguin commented 1 year ago

Solved outdated tokens.

About gameplay.gog.com and notification-pusher.gog.com, we should check how Galaxy behaves in that case