astrandb / miele

A modern integration for Miele devices in Home Assistant
MIT License
204 stars 30 forks source link

[Bug] Setting up config flow with NGINX SSL proxy results in 504 error #197

Open aturri opened 1 year ago

aturri commented 1 year ago

Bug ??

When setting up the integration in a new environment, the configuration flow cannot start and it shows the following error on frontend:

Impossibile caricare il flusso di configurazione: <html> <head><title>504 Gateway Time-out</title></head> <body> <center><h1>504 Gateway Time-out</h1></center> <hr><center>nginx</center> </body> </html> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page --> <!-- a padding to disable MSIE and Chrome friendly error page -->

I was not able to figure out why, but it happens in environments where there is a NGINX SSL proxy and with the following configuration: http: use_x_forwarded_for: true trusted_proxies: - 172.30.33.0/24 If I remove these lines from configuration file, then the config flow works correctly. If I try to start a new config flow after setting up the first one, it work too, even if there is the above configuration.

What version of the integration are you using?

miele-0.1.4

Anything in the logs that might be useful for us?

No response

Additional information

No response

astrandb commented 1 year ago

This is odd... I am running all my instances of HA behind a haproxy reverse proxy service in my routers. The proxy is taking care of the SSL processing. I have the same http: setup as you have., except that trusted_proxies specifically points to the gateway (e.g. 192.168.10.1) Is the 504 error generated by your reverse proxy? Is your problem specific to the miele integration? I cannot really see that we handle http requests differently when setting up the config flow than we do during normal operation.

aturri commented 1 year ago

I don't know who is generating the 504 error and neither which is the URL that is generating that error. However it's specific to the Miele integration.

I cannot really see that we handle http requests differently when setting up the config flow than we do during normal operation.

Exactly the same... I'll try to investigate

bradleykite commented 1 year ago

I've just installed this integration and just get a spinning circle when trying to configure it - Im accessing my home assistant via Nabu Casa (https://xxxxxxxxxx.ui.nabu.casa/) which I guess is a reverse proxy of sorts.

I'm not currently on my local LAN so can test further later on, but I suspect this might be the same issue?

astrandb commented 1 year ago

@bradleykite This is the first report that there is a problem with setup through Nabu Casa. Please try to set up the integration from LAN.

bradleykite commented 1 year ago

Hi, OK I've been able to test a little more.

On clicking on "Add Integration" and then selecting "Miele", the UI just displays "Please wait, starting configuration wizard for Miele" - the pending request is a POST for /api/config/config_entries/flow

image

The POST data is: {"handler":"miele","show_advanced_options":true}

After waiting 21 mins, the browser closed the TLS connection and the UI never allows the integration to be configured.

image

I'm going directly to the Home Assistant IP - no reverse proxy or Nabu Casa.

At the same time, the main hassio log file displays essentially that it detected the browser close the TLS connection

2023-01-10 16:28:19.932 ERROR (MainThread) [homeassistant] Error doing job: protocol.resume_writing() failed Traceback (most recent call last): File "/usr/local/lib/python3.10/asyncio/transports.py", line 300, in _maybe_resume_protocol self._protocol.resume_writing() File "/usr/local/lib/python3.10/asyncio/sslproto.py", line 522, in resume_writing self._app_protocol.resume_writing() File "/usr/local/lib/python3.10/site-packages/aiohttp/base_protocol.py", line 31, in resume_writing assert self._paused AssertionError

Not sure what else I can provide to help troubleshoot this?

astrandb commented 1 year ago

@bradleykite Moving your issue to separate issue #198

aturri commented 1 year ago

Hi, I've experienced the same issue with another custom integration. It looks like to be a common problem with NGINX ssl proxy and Let's encrypt certificate. As a workaround I was able to start config flow by using the local IP address of the Pi with HA installed.

https://community.home-assistant.io/t/504-gateway-time-out-during-update/171010

I think that we could close this issue, as it is not related to this integration.

Thanks Andrea

DerDreschner commented 1 year ago

Hey there,

I try to setup my Miele washing machine. Unfortunately, I run into the same timeout error when using my Nginx SSL proxy. When accessing the HA instance directly without SSL proxy inbetween, I just get the loading circle without any changes even after minutes of waiting. I'm using a totally fresh install of the HAOS in a virtual machine hosted by KVM. Any other integrations can be set up without problems.

Is there anything I can try/set to acquire more information about what's going on?

Thanks! David

DerDreschner commented 1 year ago

Hey again, guess I found the problem. I have a native IPv6 internet access and distribute a public IPv6 address to each device in my network. After disabling DHCPv6 for my network interface of the HAOS, I'm able to setup the integration successfully.

So, I guess there might be some problem with accessing the Miele cloud over IPv6 here.

alexboss commented 1 year ago

I encountered the same issue as the original reporter, and fixed it disabling in configuration.yaml:

#http:
#  use_x_forwarded_for: true
#  trusted_proxies:
#    - 172.30.32.1
#    - 127.0.0.1
#    - 10.0.0.2

Unfortunately, the disabling IPv6 trick did not have any impact.

Now I had to revert the http in the configuration.yaml, hope it won't break the integration.