From b20ae393f1129f97eea4d9b70f44bf2309cfbd65 Mon Sep 17 00:00:00 2001 From: Matt Stancliff Date: Wed, 19 Feb 2014 17:26:33 -0500 Subject: [PATCH 1/2] Fix "can't bind to address" error reporting. Report the actual port used for the listening attempt instead of server.port. Originally, Redis would just listen on server.port. But, with clustering, Redis uses a Cluster Port too, so we can't say server.port is always where we are listening. If you tried to launch Redis with a too-high port number (any port where Port+10000 > 65535), Redis would refuse to start, but only print an error saying it can't connect to the Redis port. This patch fixes much confusions. --- src/redis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redis.c b/src/redis.c index 0d1686a0..817943e3 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1581,7 +1581,7 @@ int listenToPort(int port, int *fds, int *count) { redisLog(REDIS_WARNING, "Creating Server TCP listening socket %s:%d: %s", server.bindaddr[j] ? server.bindaddr[j] : "*", - server.port, server.neterr); + port, server.neterr); return REDIS_ERR; } (*count)++; From ce68caea371cc75378c2261927c953fbd27147c7 Mon Sep 17 00:00:00 2001 From: Matt Stancliff Date: Wed, 19 Feb 2014 17:30:07 -0500 Subject: [PATCH 2/2] Cluster: error out quicker if port is unusable The default cluster control port is 10,000 ports higher than the base Redis port. If Redis is started on a too-high port, Cluster can't start and everything will exit later anyway. --- src/cluster.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/cluster.c b/src/cluster.c index f47799ac..52ace9eb 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -329,6 +329,19 @@ void clusterInit(void) { /* We need a listening TCP port for our cluster messaging needs. */ server.cfd_count = 0; + + /* Port sanity check II + The other handshake port check is triggered too late to stop + us from trying to use a too-high cluster port number. + */ + if (server.port > (65535-REDIS_CLUSTER_PORT_INCR)) { + redisLog(REDIS_WARNING, "Redis port number too high. " + "Cluster communication port is 10,000 port " + "numbers higher than your Redis port. " + "Your Redis port number must be " + "lower than 55535."); + } + if (listenToPort(server.port+REDIS_CLUSTER_PORT_INCR, server.cfd,&server.cfd_count) == REDIS_ERR) {