b-jesch / service.fritzbox.callmonitor

Fritzbox callmonitor shows incoming/outgoing calls and pause audio/video/tv while connecting
GNU General Public License v2.0
13 stars 2 forks source link

Connection to FritzBox frequently timeouts #13

Open panik105 opened 2 years ago

panik105 commented 2 years ago

I'm using Kodi Matrix on a RaspberryPi4 (Osmc-Distribution) with fritz callmonitor 3.08-matrix wih a FritzBox 7490 (FritzOs 7.29). It doesnt work (no reaction at all to calls). Used to work before, cant say since when it doesnt work anymore.

Here is some log snippet:

2022-06-18 15:47:09.232 T:925 INFO : [service.fritzbox.callmonitor] Connected, listen to fritz.box on port 1012 2022-06-18 15:47:10.733 T:925 ERROR : [service.fritzbox.callmonitor] Connection error, communication failure or other exception occured 2022-06-18 15:47:10.733 T:925 ERROR : [service.fritzbox.callmonitor] At line 356: timeout 2022-06-18 15:47:10.733 T:925 ERROR : [service.fritzbox.callmonitor] ('timed out',) 2022-06-18 15:48:10.736 T:925 INFO : [service.fritzbox.callmonitor] Connected, listen to fritz.box on port 1012 2022-06-18 15:48:12.238 T:925 ERROR : [service.fritzbox.callmonitor] Connection error, communication failure or other exception occured 2022-06-18 15:48:12.238 T:925 ERROR : [service.fritzbox.callmonitor] At line 356: timeout 2022-06-18 15:48:12.239 T:925 ERROR : [service.fritzbox.callmonitor] ('timed out',) 2022-06-18 15:49:12.242 T:925 INFO : [service.fritzbox.callmonitor] Connected, listen to fritz.box on port 1012 2022-06-18 15:49:13.742 T:925 ERROR : [service.fritzbox.callmonitor] Connection error, communication failure or other exception occured 2022-06-18 15:49:13.743 T:925 ERROR : [service.fritzbox.callmonitor] At line 356: timeout 2022-06-18 15:49:13.743 T:925 ERROR : [service.fritzbox.callmonitor] ('timed out',)

I dont have any clue about python (especially exception-handling), but got it working again with these changes:

            except socket.timeout:
                pass
            except (socket.error, KeyError, Exception) as e:

This is of course no real solution, but maybe it gives a hint on what is happening here..

b-jesch commented 2 years ago

socket.timeout is handled by the appropiate exception handler above. Maybe the socket port (1012) on the box is not active/disabled due a factory reset or an update?

EDIT: As this exeception occurs every 60 seconds, this seems not to be a socket error on port 1012. Be sure you have enabled network access for applications on your box (german: "Zugriff für Anwendungen zulassen"). You find this in network settings.

panik105 commented 2 years ago

This is no access problem! It worked for some years, it works from other applications (e.g. volumio, vdr, etc..) and it even works with this kodi addon after applying my above patch! Furthermore, the timeout occurs in the read (line 356), not in the connect. If i read the code correctly, the timeout is set to 30s during the connect-phase and is set to 1s afterwards. It seems the socket.timeout is not reached, instead it goes to the socket.error-part, but then in the name-part of the exception is "timeout". As i said, i have next to zero knowledge about python-exceptions, so i'm sure this explanation is not coorect in a technical sense, but as i wrote my fix "handle socket.errors with the name 'timeout' like socket.timeouts" works for me :-)

b-jesch commented 2 years ago

It makes sense to comment out these lines: https://github.com/b-jesch/service.fritzbox.callmonitor/blob/cc1a392b760e1774a14a0d18497d049cd94c47e9/default.py#L366-L371 and determine which exception occurs in detail and insert a suitable exception handler - or fix it if the problem comes not from the addon. The code of the addon itself wasn't change for 10 months now. Also the addon work as expected here (FB 7362 -but hardware is outdated and don't receive updates anymore).

I would suggest you comment out the lines mentioned above and post the exact exception here. Maybe that fix the error.

panik105 commented 2 years ago

I rolled back my changes and then commented out those lines above and now i get:

2022-06-23 21:07:27.771 T:643 ERROR : EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--

As if the "except socket.timeout:" is ignored?!

b-jesch commented 2 years ago

That's indeed strange. Diving more into this I found that socket.timeout is deprecated and is replaced by OSError and - in Python 3.10 - replaced by an alias (TimeOutError): https://docs.python.org/3/library/socket.html#exceptions

Could you replace the 'except socket.error:' by 'except TimeoutError:' and see what's happened? Maybe 'except OSError:' (as in the examples above: https://docs.python.org/3/library/socket.html#example) have success too. I couldn't test this, because the addon works here as expected.

Regards

panik105 commented 2 years ago

TimeoutError didnt work, OSError works (no wonder, as debian bullseye has python 3.9). Because OSError seems to be a lot more generic than socket.timeout i wanted to narrow the scope a little bit. I tried to compare e.errno, but its always None, so my last resort is now: except OSError as e: if str(e) == 'timed out': pass else: raise So far, this works for me..

pmbert commented 6 months ago

Hi, This issue is quite old, but it does not seem to have been conclusively clarified yet. I have the same problem with service.fritzbox.callmonitor v3.0.10+matrix on Kodi 19.4 19.4.0/ Raspbian GNU/Linux 11 (bullseye), Python 3.9.2

Regularly I got a timeout with these messages: 2024-02-26 14:04:44.287 T:9781 INFO : CAddonMgr::FindAddons: service.fritzbox.callmonitor v3.0.10+matrix installed 2024-02-26 14:04:48.142 T:9813 INFO : [service.fritzbox.callmonitor] Settings loaded 2024-02-26 14:04:48.153 T:9813 INFO : [service.fritzbox.callmonitor] Connected, listen to fritz.box on port 1012 2024-02-26 14:04:48.153 T:9813 INFO : [service.fritzbox.callmonitor] Looking for all phonebook modules in /home/pi/.kodi/addons/service.fritzbox.callmonitor/resources/lib/PhoneBooks 2024-02-26 14:04:48.155 T:9813 INFO : [service.fritzbox.callmonitor] Found module file, import resources.lib.PhoneBooks.AppleCloud 2024-02-26 14:04:50.528 T:9813 INFO : [service.fritzbox.callmonitor] Yield phonebook module AppleCloud 2024-02-26 14:04:50.528 T:9813 INFO : [service.fritzbox.callmonitor] Found module file, import resources.lib.PhoneBooks.PytzBox 2024-02-26 14:04:50.534 T:9813 INFO : [service.fritzbox.callmonitor] Yield phonebook module PytzBox 2024-02-26 14:04:51.659 T:9813 INFO : [service.fritzbox.callmonitor] 317 entries from fritz.box loaded, 0 images cached 2024-02-26 14:04:52.660 T:9813 ERROR : [service.fritzbox.callmonitor] Connection error, communication failure or other exception occured 2024-02-26 14:04:52.660 T:9813 ERROR : [service.fritzbox.callmonitor] At line 354: timeout 2024-02-26 14:04:52.660 T:9813 ERROR : [service.fritzbox.callmonitor] ('timed out',)

After this change in default.py it seems to work: except (socket.error, KeyError, Exception) as e: pass # writeLog('Connection error, communication failure or other exception occured', level=xbmc.LOGERROR) # writeLog('At line %s: %s' % (sys.exc_info()[-1].tb_lineno, str(type(e).name)), xbmc.LOGERROR) # writeLog(e.args, level=xbmc.LOGERROR) # self.Mon.waitForAbort(60) # self.connect()

b-jesch commented 5 months ago

Sorry for late answer.

First, it's not good to handle/pass a global Exception. A developer will never see when an exception occurs, even when it does. A better way is to handle the the socket timeout via OSError like @panik105 does.

except OSError as e:
    if str(e) == 'timed out': pass
    else: raise