• Oran Agra's avatar
    Optionally (default) fail to start if requested bind address is not available (#7936) · 441bfa2d
    Oran Agra authored
    Background:
    #3467 (redis 4.0.0), started ignoring ENOPROTOOPT, but did that only for
    the default bind (in case bind config wasn't explicitly set).
    #5598 (redis 5.0.3), added that for bind addresses explicitly set
    (following bug reports in Debian for redis 4.0.9 and 5.0.1), it
    also ignored a bunch of other errors like EPROTONOSUPPORT which was
    requested in #3894, and also added EADDRNOTAVAIL (wasn't clear why).
    
    This (ignoring EADDRNOTAVAIL) makes redis start successfully, even if a
    certain network interface isn't up yet , in which case we rather redis
    fail and will be re-tried when the NIC is up, see #7933.
    
    However, it turns out that when IPv6 is disabled (supported but unused),
    the error we're getting is EADDRNOTAVAIL. and in many systems the
    default config file tries to bind to localhost for both v4 and v6 and
    would like to silently ignore the error on v6 if disabled.
    This means that we sometimes want to ignore EADDRNOTAVAIL and other times
    we wanna fail.
    
    So this commit changes these main things:
    1. Ignore all the errors we ignore for both explicitly requested bind
       address and a default implicit one.
    2. Add a '-' prefix to allow EADDRNOTAVAIL be ignored (by default that's
       different than the previous behavior).
    3. Restructure that function in a more readable and maintainable way see
       below.
    4. Make the default behavior of listening to all achievable by setting
      a bind config directive to * (previously only possible by omitting
      it)
    5. document everything.
    
    The old structure of this function was that even if there are no bind
    addresses requested, the loop that runs though the bind addresses runs
    at least once anyway!
    In that one iteration of the loop it binds to both v4 and v6 addresses,
    handles errors for each of them separately, and then eventually at the
    if-else chain, handles the error of the last bind attempt again!
    This was very hard to read and very error prone to maintain, instead now
    when the bind info is missing we create one with two entries, and run
    the simple loop twice.
    441bfa2d
redis.conf 84.8 KB