Hi Peter,

On Wed, Sep 12, 2018 at 02:46:52PM +0200, Peter Fröhlich wrote:
> HAProxy does not restore the configured IP address present in the
> state file but falls back to the one in the config file at startup.
> Other information like uptime counter, state, port get restored.
> This only happens if the default server address in the config file is
> an IP. This does not happen with DNS names. If we switch out the
> default server addresses '127.0.0.1' in the config with 'localhost' it
> works as expected. We found this behavior with all tested versions
> (1.8.7, 1.8.13, 1.9-dev).

This is interesting. I'm pretty sure this derivates from the initial
choice of only restoring IP addresses learned over DNS.

> 1.9-dev
> --- src/server.c 2018-09-12 12:02:48.000000000 +0000
> +++ server.c 2018-09-12 12:02:41.000000000 +0000
> @@ -4143,7 +4143,7 @@
>   goto srv_init_addr_next;
> 
>   for (srv = curproxy->srv; srv; srv = srv->next)
> - if (srv->hostname)
> + if (srv->hostname || srv->lastaddr)
>   return_code |= srv_iterate_initaddr(srv);
> 
>   srv_init_addr_next:

I just have a doubt about this one. I suspect that if you change the
address in your config file, it will be ignored, which will be a much
worse issue.

Basically the problem we have with the state file is that some fields
do not report the original value, so it's difficult to know if the
state change is more recent than the config change. And typically the
choice above was made to work around this (possibly not the most
effective way). It's important to keep in mind that a config change
must always have percedence over a state change, otherwise you'll end
up having to remove your state file to make sure config changes are
taken into account, which would be by far the worst solution.

Ideally we should have the config address in the state file so that
upon reload we can detect if the config changed, and only pick the
new config value if it changed, otherwise use the state. I *think*
(but have not tested) that a workaround to this miss and to achieve
what you need could be to use a dummy name and set "init-addr last,<ip>"
for the initial address. This way the server name will be set, not
used for resolution, and the state file will always be applied. But
similarly, any IP address change made to the config file will be
ignored as long as the entry exists in the state file. But you'll
have the option to force that if really needed by removing "last"
on the first reload which needs to enforce a config change.

Probably that some doc updates on the subject would be needed :-/

Regards,
Willy

Reply via email to