mainsail-crew / MainsailOS

This Raspberry Pi distribution for managing Klipper 3D printers with Mainsail provides all you need.
https://docs.mainsail.xyz/setup/mainsail-os
GNU General Public License v3.0
523 stars 250 forks source link

Regularly stuck at "Initializing..." using web UI #282

Open esb7 opened 5 months ago

esb7 commented 5 months ago

What happened

I regularly get stuck at "Initializing..." when accessing mainsail from a web browser on my Mac. Sometimes it works and other times it fails and will continue to fail even through reboots of the rPi hosting mainsail. It would occur on different web browsers as well.

What did you expect to happen

Web UI should be consistent and responsive, not hung.

How to reproduce

Use mainsailos.local to access the printer web UI.

Additional information

The issue seems caused by "unauthorized" errors that show up in the moonraker log:

2024-01-20 18:50:33,939 [websockets.py:on_close()] - Websocket Closed: ID: 2822839248 Close Code: 1001, Close Reason: None, Pong Time Elapsed: 8.53 2024-01-20 18:50:34,137 [websockets.py:prepare()] - Websocket Failed Authentication: HTTP 401: Unauthorized (Unauthorized) 2024-01-20 18:50:34,140 [app.py:log_request()] - 101 GET /websocket (fd70:616c:c5db:914e:18f6:e20b:5620:9152) [No User] 23.93ms

I noticed that the failed authentications all had a reported ipv6 address and on further investigation were all in a range outside of the allowed range in the trusted_clients: section in moonraker.conf. The primary / default trusted ipv6 range is FE80::/10. However that appear to exclude other local-only address ranges (including the FD70 my device had). I believe the default should be: FC00::/7.

For anybody that hits this, you can get past it by adding the following to the trusted clients: section of the moonraker.conf file:


[authorization]
...
trusted_clients:
...
    FC00::/7        <------------- add this
...```
meteyou commented 5 months ago

FE80::/10 is reservated for local ip addresses in the ipv6 network. if you network use a different network, you have to add it. you can read more informations about FE80::/10 for example here: https://en.wikipedia.org/wiki/IPv6#Link-local_address

esb7 commented 5 months ago

From what I can tell, there is a larger "Unique Local Address" range defined for IPv6 that is subtly different than link local, but is equivalent to the non-publicly routable 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 ranges in IPv4:

https://en.wikipedia.org/wiki/Unique_local_address

My local network (using UniFi network gear) appears to be set up by default to allocate IPv6 addresses in the larger FC00::/7 range (outside of the link-local range). As a result, I get the above "Initializing..." hang / "unauthorized" errors.

It seems like it should be universally safe to include the larger "Unique Local" range by default.

meteyou commented 5 months ago

Ah ok. I didn't know that. I will double check it in the team and maybe we will add it.

reneas commented 1 week ago

I have a similar problem but without the unauthorized part. For me klippy.log reads:

[websockets.py:on_close()] - Websocket Closed: ID: 548082250224 Close Code: None, Close Reason: None, Pong Time Elapsed: 3.04

and i have a mainsail-error.log:

2024/06/27 21:14:01 [error] 721#721: *24 recv() failed (104: Connection reset by peer) while proxying upgraded connection, client: 192.168.10.33, server: _, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:7125/websocket", host: "192.168.10.23"
2024/06/27 21:14:19 [error] 722#722: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.10.33, server: _, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:7125/websocket", host: "192.168.10.23"
2024/06/27 21:14:20 [error] 722#722: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.10.33, server: _, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:7125/websocket", host: "192.168.10.23"
2024/06/27 21:14:22 [error] 722#722: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.10.33, server: _, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:7125/websocket", host: "192.168.10.23"
2024/06/27 21:14:23 [error] 722#722: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.10.33, server: _, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:7125/websocket", host: "192.168.10.23"
2024/06/27 21:14:24 [error] 722#722: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.10.33, server: _, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:7125/websocket", host: "192.168.10.23"
2024/06/27 21:14:24 [error] 722#722: *11 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.10.33, server: _, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:7125/websocket", host: "192.168.10.23"
2024/06/27 21:14:25 [error] 722#722: *13 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.10.33, server: _, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:7125/websocket", host: "192.168.10.23"
2024/06/27 21:15:10 [error] 722#722: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.10.33, server: _, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:7125/websocket", host: "192.168.10.23"
2024/06/27 21:15:11 [error] 722#722: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.10.33, server: _, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:7125/websocket", host: "192.168.10.23"
2024/06/27 21:15:12 [error] 722#722: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.10.33, server: _, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:7125/websocket", host: "192.168.10.23"
2024/06/27 21:15:13 [error] 722#722: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.10.33, server: _, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:7125/websocket", host: "192.168.10.23"
2024/06/27 21:15:14 [error] 722#722: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.10.33, server: _, request: "GET /websocket HTTP/1.1", upstream: "http://127.0.0.1:7125/websocket", host: "192.168.10.23"

adding the lines suggested by @esb7 seems to have fixed it (for now)