Skip to content

Commit

Permalink
Add check in CLUSTERLINK KILL cmd to avoid freeing links to myself (v…
Browse files Browse the repository at this point in the history
…alkey-io#689)

Add check in CLUSTERLINK KILL cmd to avoid freeing cluster bus links to
myself. Also add an assert in `freeClusterLink()`.

Testing:
```
127.0.0.1:6379> debug clusterlink kill all c0404ee68574c6aa1048aaebfe90283afe51d2fc
(error) ERR Cannot free cluster link(s) to myself
```

Signed-off-by: Pierre Turin <[email protected]>
  • Loading branch information
pieturin authored Jun 25, 2024
1 parent b49eaad commit 495c35d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,7 @@ clusterLink *createClusterLink(clusterNode *node) {
* This function will just make sure that the original node associated
* with this link will have the 'link' field set to NULL. */
void freeClusterLink(clusterLink *link) {
serverAssert(link != NULL);
if (link->conn) {
connClose(link->conn);
link->conn = NULL;
Expand Down Expand Up @@ -5815,6 +5816,10 @@ int handleDebugClusterCommand(client *c) {
addReplyErrorFormat(c, "Unknown node %s", (char *)c->argv[4]->ptr);
return 1;
}
if (n == server.cluster->myself) {
addReplyErrorFormat(c, "Cannot free cluster link(s) to myself");
return 1;
}

/* Terminate the link based on the direction or all. */
if (!strcasecmp(c->argv[3]->ptr, "from")) {
Expand Down

0 comments on commit 495c35d

Please sign in to comment.