snstac / pytak

PyTAK is a Python package for rapid TAK integration.
https://pytak.readthedocs.io/en/stable/
Apache License 2.0
156 stars 42 forks source link

Potentially uncaught exception for "ConnectionResetError: [Errno 104] Connection reset by peer" in "classes.py" #45

Closed henriberisha closed 1 year ago

henriberisha commented 1 year ago

Has happened that the TAK server has closed the connection . During this process an exception is generated in 'classes.py' with the following traceback:

2023-08-13 21:51:03,268 pytak INFO - Complete: <Task finished name='Task-2' coro=<RXWorker.run() done, defined at /usr/local/lib/python3.11/site-packages/pytak/classes.py:173> exception=ConnectionResetError(104, 'Connection reset by peer')> 08-13-2023 21:51:03.268Z | asyncio | ERROR:Task exception was never retrieved future: <Task finished name='Task-2' coro=<RXWorker.run() done, defined at /usr/local/lib/python3.11/site-packages/pytak/classes.py:173> exception=ConnectionResetError(104, 'Connection reset by peer')> Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pytak/classes.py", line 179, in run data: bytes = await self.readcot() ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pytak/classes.py", line 168, in readcot return await self.reader.readuntil("".encode("UTF-8")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/streams.py", line 637, in readuntil await self._wait_for_data('readuntil') File "/usr/local/lib/python3.11/asyncio/streams.py", line 522, in _wait_for_data await self._waiter File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 970, in _read_ready__get_buffer nbytes = self._sock.recv_into(buf) ^^^^^^^^^^^^^^^^^^^^^^^^^ ConnectionResetError: [Errno 104] Connection reset by peer

ampledata commented 1 year ago

This is the current expected behavior for PyTAK: Exit if you encounter an unrecoverable fatal network erro.

The recommended method for dealing with these types of fatal network errors is to run the PyTAK process under the management of systemctl. For example, the adsbcot ADS-B to TAK Gateway has a recommended systemctl configuration & instructions for enabling systemctl+adsbcot: https://adsbcot.readthedocs.io/en/latest/running.html

The fundamental reason for raising vs. passing network exceptions is that they are often a function of change in System state, e.g. network link going down, wifi disconnect, etc.