summaryrefslogtreecommitdiff
path: root/redis.conf
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2020-10-28 21:09:15 +0200
committerGitHub <noreply@github.com>2020-10-28 21:09:15 +0200
commit441bfa2dfb57e0dbfddad167bafa559b3f051b5b (patch)
treeb780b8fcbe464d81bbb37f3e01bb918030634103 /redis.conf
parentd310beb4170ebbc8985ae120ee301f9213d33e39 (diff)
downloadredis-441bfa2dfb57e0dbfddad167bafa559b3f051b5b.tar.gz
Optionally (default) fail to start if requested bind address is not available (#7936)
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.
Diffstat (limited to 'redis.conf')
-rw-r--r--redis.conf17
1 files changed, 12 insertions, 5 deletions
diff --git a/redis.conf b/redis.conf
index 119f7b6f9..4caa70f38 100644
--- a/redis.conf
+++ b/redis.conf
@@ -49,23 +49,30 @@
# for connections from all available network interfaces on the host machine.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
+# Each address can be prefixed by "-", which means that redis will not fail to
+# start if the address is not available. Being not available only refers to
+# addresses that does not correspond to any network interfece. Addresses that
+# are already in use will always fail, and unsupported protocols will always BE
+# silently skipped.
#
# Examples:
#
-# bind 192.168.1.100 10.0.0.1
-# bind 127.0.0.1 ::1
+# bind 192.168.1.100 10.0.0.1 # listens on two specific IPv4 addresses
+# bind 127.0.0.1 ::1 # listens on loopback IPv4 and IPv6
+# bind * -::* # like the default, all available interfaces
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only on the
-# IPv4 loopback interface address (this means Redis will only be able to
-# accept client connections from the same host that it is running on).
+# IPv4 and IPv6 (if available) loopback interface addresses (this means Redis
+# will only be able to accept client connections from the same host that it is
+# running on).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT OUT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-bind 127.0.0.1
+bind 127.0.0.1 -::1
# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.