Skip to content

Fix crash with CLUSTER REPLICATE for replicas with slots#12282

Open
enjoy-binbin wants to merge 2 commits intoredis:unstablefrom
enjoy-binbin:fix_cluster_crash
Open

Fix crash with CLUSTER REPLICATE for replicas with slots#12282
enjoy-binbin wants to merge 2 commits intoredis:unstablefrom
enjoy-binbin:fix_cluster_crash

Conversation

@enjoy-binbin
Copy link
Contributor

@enjoy-binbin enjoy-binbin commented Jun 8, 2023

In ac3850c, we allow replicas to switch master via CLUSTER REPLICATE.
If a replica has slots, using the command will crash the replica.

Replicas are by design not supposed to own any slots, in this PR, we update
the judgements to prevent the replica from trying to take ownership of slots.

Fixes #12268. Fixed #12717.

In ac3850c, we allow replicas to switch master via CLUSTER REPLICATE,
then modified the corresponding judgment, but forgot to modify
clusterSetMaster. If a replica has slots, using the command will crash
the replica.

Fixes redis#12268
@enjoy-binbin enjoy-binbin requested review from madolson and oranagra June 8, 2023 04:08
@enjoy-binbin
Copy link
Contributor Author

or maybe in CLUSTER REPLICATE, we should call a clusterDelNodeSlots(myself) if we find out myself is a replica.
i will try to add a test to cover it later

@CharlesChen888
Copy link
Contributor

A replica in cluster should not possess any slot.

I think we should forbid ADDSLOT and ADDSLOTRANGE to execute on a replica, and check whether "myself" has any slot in CLUSTER REPLICATE, instead of deleting slots from a node which should not have any.

@enjoy-binbin
Copy link
Contributor Author

A replica in cluster should not possess any slot.
I think we should forbid ADDSLOT and ADDSLOTRANGE to execute on a replica, and check whether "myself" has any slot in CLUSTER REPLICATE, instead of deleting slots from a node which should not have any.

yeah, i agree with this. I checked it and didn't see any restrictions on replicas, and since the code been there forever, i plan to keep it for now. anyway, i am ok with both, let's see what other people say

@soloestoy
Copy link
Contributor

A replica in cluster should not possess any slot.

I think we should forbid ADDSLOT and ADDSLOTRANGE to execute on a replica, and check whether "myself" has any slot in CLUSTER REPLICATE, instead of deleting slots from a node which should not have any.

+1

@madolson
Copy link
Contributor

A replica in cluster should not possess any slot.

Yeah, replicas are by design not supposed to own any slots. I would rather update the judgements to prevent the replica from trying to take ownership of slots. I'm fairly sure it was just an oversight at the time, the code has always been fairly fragile.

@enjoy-binbin
Copy link
Contributor Author

and check whether "myself" has any slot in CLUSTER REPLICATE

we do this when master:

        /* If the instance is currently a master, it should have no assigned
         * slots nor keys to accept to replicate some other node.
         * Slaves can switch to another master without issues. */
        if (nodeIsMaster(myself) &&
            (myself->numslots != 0 || dictSize(server.db[0].dict) != 0)) {
            addReplyError(c,
                "To set a master the node must be empty and "
                "without assigned slots.");
            return;
        }

now with the new changes, do we need to check the replicas?

@enjoy-binbin enjoy-binbin mentioned this pull request Aug 15, 2023
@oranagra
Copy link
Member

oranagra commented Aug 15, 2023

@madolson please take another look. IIUC it's not urgent, but there's probably no reason not to fix it one way or the other.

@CLAassistant
Copy link

CLAassistant commented Mar 24, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sundb sundb removed this from Redis 8.2 Aug 19, 2025
@sundb sundb added this to Redis 8.4 Aug 19, 2025
@sundb sundb removed this from Redis 8.4 Nov 6, 2025
@github-project-automation github-project-automation bot moved this to Backlog in Redis Backlog Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

6 participants