Phoenix LiveView loses state

I have a simple LiveView component, a form with some validations. I found that on my live system the form randomly uses state after a short time (about a minute maybe).

I run Phoenix using Docket/k8s and have the Phoenix app running multiple times with different parameters. I assume that is the issue, that the websocket connection switches between nodes which have different states?

How do I fix this? I wouldn’t mind if only one node provides websocket connections. Or do I need to go for actual clustering?

It should only do this if the websocket connection disconnects. As long as the socket is connected it will not lose state. I’d make sure that you aren’t seeing any crashes in the logs, since if the socket process dies you will also lose state. If the phoenix container is terminated then obviously a reconnection will be needed as well, so I’d check that too.

1 Like