Add check in CLUSTERLINK KILL cmd to avoid freeing links to myself (#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 <pieturin@amazon.com>
This commit is contained in:
Pierre 2024-06-25 15:18:30 -07:00 committed by GitHub
parent b49eaad367
commit 495c35d918
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;
@ -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")) {