From 92e847d054562f2a7b8a3f25aaada2803b6c0ad3 Mon Sep 17 00:00:00 2001 From: Patrick Valsecchi Date: Thu, 7 Nov 2019 08:49:19 +0100 Subject: [PATCH] Redis sentinel kill pubsub client connections as well When a redis instance becomes a slave, sentinel also kills pubsub clients. Closes #6545 --- src/sentinel.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/sentinel.c b/src/sentinel.c index 0490db4e9..d5f22b97f 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -465,6 +465,12 @@ struct redisCommand sentinelcmds[] = { {"hello",helloCommand,-2,"no-script fast",0,NULL,0,0,0,0,0} }; +/* List of client types that are killed when an instance becomes a slave */ +const char* killedClientTypes[] = { + "normal", + "pubsub" +}; + /* This function overwrites a few normal Redis config default with Sentinel * specific defaults. */ void initSentinelConfig(void) { @@ -3949,6 +3955,7 @@ char *sentinelGetLeader(sentinelRedisInstance *master, uint64_t epoch) { int sentinelSendSlaveOf(sentinelRedisInstance *ri, char *host, int port) { char portstr[32]; int retval; + unsigned int curType; ll2string(portstr,sizeof(portstr),port); @@ -3993,11 +4000,14 @@ int sentinelSendSlaveOf(sentinelRedisInstance *ri, char *host, int port) { * an issue because CLIENT is variadic command, so Redis will not * recognized as a syntax error, and the transaction will not fail (but * only the unsupported command will fail). */ - retval = redisAsyncCommand(ri->link->cc, - sentinelDiscardReplyCallback, ri, "%s KILL TYPE normal", - sentinelInstanceMapCommand(ri,"CLIENT")); - if (retval == C_ERR) return retval; - ri->link->pending_commands++; + for (curType = 0; curType < sizeof(killedClientTypes)/sizeof(killedClientTypes[0]); ++curType) { + retval = redisAsyncCommand(ri->link->cc, + sentinelDiscardReplyCallback, ri, "%s KILL TYPE %s", + sentinelInstanceMapCommand(ri,"CLIENT"), + killedClientTypes[curType]); + if (retval == C_ERR) return retval; + ri->link->pending_commands++; + } retval = redisAsyncCommand(ri->link->cc, sentinelDiscardReplyCallback, ri, "%s",