Skip to content

Conversation

@MeirShpilraien
Copy link

@MeirShpilraien MeirShpilraien commented Oct 2, 2022

PR #9320 introduces initialization order changes. Now cluster is initialized after modules.
This changes causes a crash if the module uses RM_Call inside the load function
on cluster mode (the code will try to access server.cluster which at this point is NULL).

To solve it, separate cluster initialization into 2 phases:

  1. Structure initialization that happened before the modules initialization
  2. Listener initialization that happened after.

Test was added to verify the fix.

The following [PR](redis#9320) instoduces
initialization order changes. Now cluster is initialized after modules.
This changes causes a crash if the module uses RM_Call inside the load
function on cluster mode (the code will try to access `server.cluster`
which at this point is NULL).

To solve it, seperate cluster initialization into 2 phases:
1. Structure initialization that happened before the modules initialization
2. Listener initialization that happened after.

Test was added to verify the fix.
Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this segment belongs in clusterInit
it could be that some RM_Call command would need these.
maybe it doesn't matter though, and we rather not mess up the blame log?
@madolson WDYT?

    /* Initialize data for the Slot to key API. */
    slotToKeyInit(server.db);
    /* The slots -> channels map is a radix tree. Initialize it here. */
    server.cluster->slots_to_channels = raxNew();
    /* Set myself->port/cport/pport to my listening ports, we'll just need to
     * discover the IP address via MEET messages. */
    deriveAnnouncedPorts(&myself->port, &myself->pport, &myself->cport);
    server.cluster->mf_end = 0;
    server.cluster->mf_slave = NULL;
    resetManualFailover();
    clusterUpdateMyselfFlags();
    clusterUpdateMyselfIp();
    clusterUpdateMyselfHostname();

@madolson
Copy link
Contributor

I agree with Oran, I don't think we should just bisect the current clusterInit at the position we need for initializing the listeners, since it becomes more confusing in the future to understand what goes where. I would expect if we extract out the listener initialization code into a separate function "clusterInitListeners", hopefully that will protect the git blame enough.

@oranagra
Copy link
Member

oranagra commented Oct 12, 2022

triggered cluster (and TLS) CI:
https://github.com/redis/redis/actions/runs/3233090930

@oranagra
Copy link
Member

@MeirShpilraien looks like there's a crush in clusterInit when using TLS

@MeirShpilraien
Copy link
Author

@oranagra I hope I fixed it. Can you trigger it again?

@oranagra
Copy link
Member

passed.

@oranagra oranagra merged commit eb6acca into redis:unstable Oct 12, 2022
madolson pushed a commit to madolson/redis that referenced this pull request Apr 19, 2023
PR redis#9320 introduces initialization order changes. Now cluster is initialized after modules.
This changes causes a crash if the module uses RM_Call inside the load function
on cluster mode (the code will try to access `server.cluster` which at this point is NULL).

To solve it, separate cluster initialization into 2 phases:
1. Structure initialization that happened before the modules initialization
2. Listener initialization that happened after.

Test was added to verify the fix.
enjoy-binbin pushed a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
PR redis#9320 introduces initialization order changes. Now cluster is initialized after modules.
This changes causes a crash if the module uses RM_Call inside the load function
on cluster mode (the code will try to access `server.cluster` which at this point is NULL).

To solve it, separate cluster initialization into 2 phases:
1. Structure initialization that happened before the modules initialization
2. Listener initialization that happened after.

Test was added to verify the fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants