zwave-js / zwave-js-ui

Full featured Z-Wave Control Panel UI and MQTT gateway. Built using Nodejs, and Vue/Vuetify
https://zwave-js.github.io/zwave-js-ui
MIT License
984 stars 201 forks source link

zwave-js-ui, nginx, HA websocket issue #2769

Closed kantlivelong closed 2 years ago

kantlivelong commented 2 years ago

This is a bit lengthy but here it goes...

I've got a seemingly weird issue with zwave-js-ui and nginx. For whatever reason the websocket connection only works if I CTRL+F5(no-cache reload). If I do a simple F5 refresh afterwards the websocket connection fails.

Digging into this further I've found that on a regular page load/refresh zwave-js-ui or socket.io is returning what seems to be bogus sid and it's always the same sid. If I no-cache refresh a valid sid is returned and the websocket session connects without issue.

I've checked the issue trackers for zwave-js-ui and socket.io as well as done some general web searching to see what I can find. From what I can tell my nginx config should be fine as it does work via CLI via wscat and does work on a no-cache reload.

My setup is pretty simple but is as follows

Config: https://pastebin.com/YkytXi15

Checking the Firefox dev console on a regular load/reload I see the first request to socket.io via https://homeassistant.FQDN:8124/_/zwavejs2mqtt/socket.io/?EIO=4&transport=polling&t=OGVHQXK and it receives the response 0{"sid":"QHEjB7LIw5v_fO0rAAEl","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":20000,"maxPayload":1000000}. The sid in this response is always the same.

When I no-cache reload I see the same initial connection but with a valid sid. I can verify the same behavior with curl

Mid ticket update:

So I've found that zwave-js-ui will work fine until I sign into HA. Once I sign into HA the problematic behavior occurs.

HA URL: https://homeassistant.FQDN:8124/ zwave-js-ui URL: https://homeassistant.FQDN:8124/_/zwavejs2mqtt/

I found that simply adding an extra port (8125) to the nginx config then connecting to zwave-js-ui works perfectly at the URL above until I sign into HA at the URL above.

Is there some sort of cookie or session storage collision going on here?

robertsLando commented 2 years ago

Never seen such kind of problems, just to be clear, are you speaking about the zwave-js UI websocket or the home hassistant websocket? Is your problem on the z-ui UI side or home assistant side?

kantlivelong commented 2 years ago

The UI Websocket. I have the HA websocket disabled.

robertsLando commented 2 years ago

At first sight it seems to me a cache problem in nginx configuration, I'm not an nginx expert but I know hass addon works without any problem (and it's using nginx) and I also have a working example using nginx

AaronSeibert commented 2 years ago

Your location / matches all requests, and you have websocket headers in there. If you don't need the websocket on / and only on the zigbee/hass/zwavejs parts can probably take it out of there.

FWIW, it may be easier to use a separate host header for each. Would make the configs easier to troubleshoot vs having child paths.