summaryrefslogtreecommitdiff
path: root/tests/modules
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 /tests/modules
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 'tests/modules')
-rw-r--r--tests/modules/basics.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/modules/basics.c b/tests/modules/basics.c
index 55b36fa5e..b6f9766c6 100644
--- a/tests/modules/basics.c
+++ b/tests/modules/basics.c
@@ -893,6 +893,28 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
if (RedisModule_Init(ctx,"test",1,REDISMODULE_APIVER_1)
== REDISMODULE_ERR) return REDISMODULE_ERR;
+ /* Perform RM_Call inside the RedisModule_OnLoad
+ * to verify that it works as expected without crashing.
+ * The tests will verify it on different configurations
+ * options (cluster/no cluster). A simple ping command
+ * is enough for this test. */
+ RedisModuleCallReply *reply = RedisModule_Call(ctx, "ping", "");
+ if (RedisModule_CallReplyType(reply) != REDISMODULE_REPLY_STRING) {
+ RedisModule_FreeCallReply(reply);
+ return REDISMODULE_ERR;
+ }
+ size_t len;
+ const char *reply_str = RedisModule_CallReplyStringPtr(reply, &len);
+ if (len != 4) {
+ RedisModule_FreeCallReply(reply);
+ return REDISMODULE_ERR;
+ }
+ if (memcmp(reply_str, "PONG", 4) != 0) {
+ RedisModule_FreeCallReply(reply);
+ return REDISMODULE_ERR;
+ }
+ RedisModule_FreeCallReply(reply);
+
if (RedisModule_CreateCommand(ctx,"test.call",
TestCall,"write deny-oom",1,1,1) == REDISMODULE_ERR)
return REDISMODULE_ERR;