kbr / fritzconnection

Python-Tool to communicate with the AVM Fritz!Box by the TR-064 protocol and the AHA-HTTP-Interface
MIT License
303 stars 59 forks source link

Timeout after 30 Min #141

Closed tichachm closed 1 year ago

tichachm commented 2 years ago

Hi I am using the homeassistant integration for FritzBox Call Monitor, I think it is using this lib to connect to FritzBox.

I can also reproduce this issue calling fritzmonitor like described here: https://fritzconnection.readthedocs.io/en/1.9.1/sources/call_monitoring.html

It is working fine but after about 30 minutes it does not react on any call.

It looks like the problem is in fritzconnection.core.fritzmonitor

If I add following lines in '_get_connected_socket' after 'sock.settimeout(self.timeout)' the problem seems to be fixed:

sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 10) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 100) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 5)

see: https://github.com/home-assistant/core/issues/61880

kbr commented 2 years ago

There was an extensive discussion about this in another thread #76 – waiting to get reopen in case of more knowledge about the socket options. Problem has been, that the options are partly OS dependent and the documentation, if any, was not very helpful. What I absolutely want to avoid is programming by guessing.

tichachm commented 2 years ago

Thanks for the fast answer and link to the other discussion. I think my issue is network-related. Here some more information about the setup: HomeAssistant is running in a docker container in host mode on a Linux VM. But I also get this issue with the host system and on Windows, everywhere after about 30 minutes.

Between FritzBox and my Server/PC there is a additional Router (Lancom) i think this one is causing this problem. There are some routing/firewall settings for TCP-Aging but until now I could not figure out what to change.

kbr commented 1 year ago

I like to close this – again with referring to #76. Keep this as "hibernated" work in progress, and wake up on getting proper documentation.