Commit cee6d309 authored by Viktor Söderqvist's avatar Viktor Söderqvist Committed by Oran Agra
Browse files

Don't crash when adding a forgotten node to blacklist twice (#12702)

Add a defensive checks to prevent double freeing a node from the cluster blacklist.

(cherry picked from commit 8d675950)
parent cf013b83
...@@ -1134,6 +1134,9 @@ void clusterReset(int hard) { ...@@ -1134,6 +1134,9 @@ void clusterReset(int hard) {
} }
dictReleaseIterator(di); dictReleaseIterator(di);
/* Empty the nodes blacklist. */
dictEmpty(server.cluster->nodes_black_list, NULL);
/* Hard reset only: set epochs to 0, change node ID. */ /* Hard reset only: set epochs to 0, change node ID. */
if (hard) { if (hard) {
sds oldname; sds oldname;
...@@ -2655,8 +2658,7 @@ void clusterProcessPingExtensions(clusterMsg *hdr, clusterLink *link) { ...@@ -2655,8 +2658,7 @@ void clusterProcessPingExtensions(clusterMsg *hdr, clusterLink *link) {
clusterNode *n = clusterLookupNode(forgotten_node_ext->name, CLUSTER_NAMELEN); clusterNode *n = clusterLookupNode(forgotten_node_ext->name, CLUSTER_NAMELEN);
if (n && n != myself && !(nodeIsSlave(myself) && myself->slaveof == n)) { if (n && n != myself && !(nodeIsSlave(myself) && myself->slaveof == n)) {
sds id = sdsnewlen(forgotten_node_ext->name, CLUSTER_NAMELEN); sds id = sdsnewlen(forgotten_node_ext->name, CLUSTER_NAMELEN);
dictEntry *de = dictAddRaw(server.cluster->nodes_black_list, id, NULL); dictEntry *de = dictAddOrFind(server.cluster->nodes_black_list, id);
serverAssert(de != NULL);
uint64_t expire = server.unixtime + ntohu64(forgotten_node_ext->ttl); uint64_t expire = server.unixtime + ntohu64(forgotten_node_ext->ttl);
dictSetUnsignedIntegerVal(de, expire); dictSetUnsignedIntegerVal(de, expire);
clusterDelNode(n); clusterDelNode(n);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment