Hi Bren, On Mon, Aug 22, 2022 at 05:20:37PM +0000, Bren wrote: > Hello, > > We've been seeing another minor issue I've been meaning to ask about. We're > using a server state file: > > server-state-file /var/lib/haproxy/server_state > > In my systemd config for haproxy I've added a couple lines to save the server > state on reload/stop: > > ExecReload=/usr/local/sbin/haproxy -Ws -f $CONFIG -c -q $EXTRAOPTS > ExecReload=/opt/bin/save_server_state.sh > ExecReload=/bin/kill -USR2 $MAINPID > ExecStop=/opt/bin/save_server_state.sh > > The script simply runs: > > echo "show servers state" | socat /var/run/haproxy/admin.sock - > \ > /var/lib/haproxy/server_state > > I've noticed that when I change the port on a backend server and reload, > haproxy does not update the port for that server. I have to shut down > haproxy, delete the state file, then start it back up for it to update the > port (changing the port and renaming the server, reloading, then renaming it > back and reloading again works too). > > When I change other parts of the config, for example, if I add "disabled" to > a server line and reload, haproxy updates the status of the server. It seems > like haproxy isn't looking at the port when deciding if it should update the > config for a server when using a state file. > > Is this expected behavior?
It's neither expected nor unexpected. The problem is that the state file only reflects *last* known values for elements that come both from the config and from dynamic changes (e.g. CLI commands or DNS SRV records). As such when haproxy restarts its parses its config and updates it based on the state file. Some discrepancies are resolved by considering the config first, but not all can otherwise the state file would be useless. The right way to proceed for the state file would be to provide both the config and the dynamic elements so that on startup, the entry is ignored if the config changed, but it's not how it currently works. Thus as you see it's a design issue. There's already an open issue on this topic: https://github.com/haproxy/haproxy/issues/953 It just happens that this is a tedious task and that there are few enough users affected by such issues to convince anyone to dive into this :-/ Regards, Willy

