nickvsnetworking / pyhss

Python HSS / Diameter Server
GNU Affero General Public License v3.0
71 stars 59 forks source link

Refactor hss.py, add teardown handling for threads, fix infinite threading #116

Closed davidkneipp closed 1 year ago

davidkneipp commented 1 year ago

Use of Async functions with redis enabled no longer causes threading based crashes:

Feb 28 04:51:21 hss06 python3[114218]: Exception in thread Thread-909: Feb 28 04:51:21 hss06 python3[114218]: Traceback (most recent call last): Feb 28 04:51:21 hss06 python3[114218]: File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner Feb 28 04:51:21 hss06 python3[114218]: self.run() Feb 28 04:51:21 hss06 python3[114218]: File "/usr/lib/python3.8/threading.py", line 870, in run Feb 28 04:51:21 hss06 python3[114218]: self._target(*self._args, **self._kwargs) Feb 28 04:51:21 hss06 python3[114218]: File "hss.py", line 329, in manage_client Feb 28 04:51:21 hss06 python3[114218]: data = clientsocket.recv(32) Feb 28 04:51:21 hss06 python3[114218]: File "/usr/local/lib/python3.8/dist-packages/gevent/_socketcommon.py", line 663, in recv Feb 28 04:51:21 hss06 python3[114218]: self._wait(self._read_event) Feb 28 04:51:21 hss06 python3[114218]: File "src/gevent/_hub_primitives.py", line 317, in gevent._gevent_c_hub_primitives.wait_on_socket Feb 28 04:51:21 hss06 python3[114218]: File "src/gevent/_hub_primitives.py", line 322, in gevent._gevent_c_hub_primitives.wait_on_socket Feb 28 04:51:21 hss06 python3[114218]: File "src/gevent/_hub_primitives.py", line 304, in gevent._gevent_c_hub_primitives._primitive_wait Feb 28 04:51:21 hss06 python3[114218]: File "src/gevent/_hub_primitives.py", line 46, in gevent._gevent_c_hub_primitives.WaitOperationsGreenlet.wait Feb 28 04:51:21 hss06 python3[114218]: File "src/gevent/_hub_primitives.py", line 46, in gevent._gevent_c_hub_primitives.WaitOperationsGreenlet.wait Feb 28 04:51:21 hss06 python3[114218]: File "src/gevent/_hub_primitives.py", line 55, in gevent._gevent_c_hub_primitives.WaitOperationsGreenlet.wait Feb 28 04:51:21 hss06 python3[114218]: File "src/gevent/_waiter.py", line 154, in gevent._gevent_c_waiter.Waiter.get Feb 28 04:51:21 hss06 python3[114218]: File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch Feb 28 04:51:21 hss06 python3[114218]: File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch Feb 28 04:51:21 hss06 python3[114218]: File "src/gevent/_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch Feb 28 04:51:21 hss06 python3[114218]: File "src/gevent/_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch Feb 28 04:51:21 hss06 python3[114218]: greenlet.error: cannot switch to a different thread

Threads now cleanup properly, and no longer spawn infinitely. No other errors observed post refactor, UE attach & IMS attach ok.