summaryrefslogtreecommitdiff
path: root/src/cluster.c
diff options
context:
space:
mode:
authorMeir Shpilraien (Spielrein) <meir@redis.com>2022-10-12 13:09:51 +0300
committerGitHub <noreply@github.com>2022-10-12 13:09:51 +0300
commiteb6accad40577cd11846c4f5391c6351eb46d7b6 (patch)
tree6247b6d7678800135b5e6b349bb99a131e78494e /src/cluster.c
parenta370bbe263009f806b3f9454674342d350f6475a (diff)
downloadredis-eb6accad40577cd11846c4f5391c6351eb46d7b6.tar.gz
Fix crash on RM_Call inside module load (#11346)
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.
Diffstat (limited to 'src/cluster.c')
-rw-r--r--src/cluster.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/cluster.c b/src/cluster.c
index b1b4e645d..f7603611f 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -694,11 +694,31 @@ void clusterInit(void) {
exit(1);
}
+ /* 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();
+}
+
+void clusterInitListeners(void) {
if (connectionIndexByType(connTypeOfCluster()->get_type(NULL)) < 0) {
serverLog(LL_WARNING, "Missing connection type %s, but it is required for the Cluster bus.", connTypeOfCluster()->get_type(NULL));
exit(1);
}
+ int port = server.tls_cluster ? server.tls_port : server.port;
connListener *listener = &server.clistener;
listener->count = 0;
listener->bindaddr = server.bindaddr;
@@ -714,23 +734,6 @@ void clusterInit(void) {
if (createSocketAcceptHandler(&server.clistener, clusterAcceptHandler) != C_OK) {
serverPanic("Unrecoverable error creating Redis Cluster socket accept handler.");
}
-
- /* 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();
}
/* Reset a node performing a soft or hard reset: