Skip to content

Commit 6cbea7d

Browse files
committed
Prevent replicas from sending commands that interact with keyspace (#8868)
This solves an issue reported in #8712 in which a replica would bypass the client write pause check and cause an assertion due to executing a write command during failover. The fact is that we don't expect replicas to execute any command other than maybe REPLCONF and PING, etc. but matching against the ADMIN command flag is insufficient, so instead i just block keyspace access for now. (cherry picked from commit 46f4ebb)
1 parent 8cfa37f commit 6cbea7d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: src/server.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -3985,6 +3985,8 @@ int processCommand(client *c) {
39853985
return C_OK;
39863986
}
39873987

3988+
int is_read_command = (c->cmd->flags & CMD_READONLY) ||
3989+
(c->cmd->proc == execCommand && (c->mstate.cmd_flags & CMD_READONLY));
39883990
int is_write_command = (c->cmd->flags & CMD_WRITE) ||
39893991
(c->cmd->proc == execCommand && (c->mstate.cmd_flags & CMD_WRITE));
39903992
int is_denyoom_command = (c->cmd->flags & CMD_DENYOOM) ||
@@ -4194,7 +4196,7 @@ int processCommand(client *c) {
41944196
c->cmd->proc != discardCommand &&
41954197
c->cmd->proc != watchCommand &&
41964198
c->cmd->proc != unwatchCommand &&
4197-
c->cmd->proc != resetCommand &&
4199+
c->cmd->proc != resetCommand &&
41984200
!(c->cmd->proc == shutdownCommand &&
41994201
c->argc == 2 &&
42004202
tolower(((char*)c->argv[1]->ptr)[0]) == 'n') &&
@@ -4206,6 +4208,14 @@ int processCommand(client *c) {
42064208
return C_OK;
42074209
}
42084210

4211+
/* Prevent a replica from sending commands that access the keyspace.
4212+
* The main objective here is to prevent abuse of client pause check
4213+
* from which replicas are exempt. */
4214+
if ((c->flags & CLIENT_SLAVE) && (is_may_replicate_command || is_write_command || is_read_command)) {
4215+
rejectCommandFormat(c, "Replica can't interract with the keyspace");
4216+
return C_OK;
4217+
}
4218+
42094219
/* If the server is paused, block the client until
42104220
* the pause has ended. Replicas are never paused. */
42114221
if (!(c->flags & CLIENT_SLAVE) &&

0 commit comments

Comments
 (0)