On Thu, 13 Sep 2018, 07:52 Willy Tarreau, <[email protected]> wrote:
> 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.

This makes sense and I expected that much, reading the source.
But the documentation didn't reflect that so I took it as a bug.

> 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.

Thanks, I'll try that.
That said, I'm actually happy with just setting 'localhost' everywhere.
We are using this config in our service discovery layer and set all the
backend servers to an invalid default value - the real settings always
get set over the socket or over the state file in case of a restart.

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

I agree, as now its not clear that IPs get ignored in the state file if the
server does not have a DNS name set in the config file.

Would our use case of setting the backend servers only through the socket,
and the necessary workaround of setting the server entries to 'localhost'
be worth a 'Notes:' entry in the 'load-server-state-from-file' section?

Kind regards,
Peter

Reply via email to