From 089cbe643f3922aec26d483548e14c8d10f74e0c Mon Sep 17 00:00:00 2001
From: antirez <antirez@gmail.com>
Date: Thu, 31 Jan 2013 17:19:21 +0100
Subject: [PATCH] Sentinel: advertise the promoted slave address only after
 successful setup.

---
 src/sentinel.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/sentinel.c b/src/sentinel.c
index 8009e5ed9..fc857344c 100644
--- a/src/sentinel.c
+++ b/src/sentinel.c
@@ -2035,8 +2035,16 @@ void sentinelCommand(redisClient *c) {
         } else {
             sentinelAddr *addr = ri->addr;
 
-            if ((ri->flags & SRI_FAILOVER_IN_PROGRESS) && ri->promoted_slave)
+            /* If we are in the middle of a failover, and the slave was
+             * already successfully switched to master role, we can advertise
+             * the new address as slave in order to allow clients to talk
+             * with the new master ASAP. */
+            if ((ri->flags & SRI_FAILOVER_IN_PROGRESS) &&
+                ri->promoted_slave &&
+                ri->failover_state >= SENTINEL_FAILOVER_STATE_RECONF_SLAVES)
+            {
                 addr = ri->promoted_slave->addr;
+            }
             addReplyMultiBulkLen(c,2);
             addReplyBulkCString(c,addr->ip);
             addReplyBulkLongLong(c,addr->port);