Closed jbriales closed 4 years ago
BTW this state can be easily reproduced by starting spotpris2, then disconnecting from the network.
On one hand, it doesn't crash hard enough.
I use s6 to supervise the process, and like systemd, it will ensure the process is started again if it ever fails; but the spotpris2 process doesn't exit when it encounters this error, hiding the failure from any process supervisor, leaving it in a useless purgatory.
IMO, long-running processes like this will fail sometimes, and handling that is best left to a proper supervisor such as s6 or systemd.
On another hand, this issue should be handle-able without crashing.
It looks to me like BusManager.MultiBusManager.main_loop
encounters a requests.exceptions.ReadTimeout
, and then it bubbles up to __main__.main.timeout_handler
, which was triggered by GLib.timeout_add_seconds
. I guess that exceptions in loop-added timers like this don't kill the app's main process.
I peeked at some glib docs and saw for timeout_add
(and I presume this is the same for timeout_add_seconds
):
The function is called repeatedly until it returns
False
, at which point the timeout is automatically destroyed and the function will not be called again.
I think that when the exception happens, it prevents timeout_handler
from returning True
, which glib considers as good as returning False
, so it destroys that timer.
So maybe a solution could be like:
--- __main__.py 2020-05-17 12:51:37.162663698 -0400
+++ fixed.py 2020-10-17 23:45:48.642159351 -0400
@@ -58,8 +58,10 @@
manager = SingleBusManager(sp)
def timeout_handler():
- manager.main_loop()
- return True
+ try:
+ manager.main_loop()
+ except Exception as e:
+ print(e)
+ finally:
+ return True
GLib.timeout_add_seconds(1, timeout_handler)
spotpris2 seems to be crashing after a while due to time outs Should the client deal with these rather than crashing?