diff --git a/src/module.c b/src/module.c index 38d0c2d96..288423920 100644 --- a/src/module.c +++ b/src/module.c @@ -12194,11 +12194,15 @@ int moduleLoad(const char *path, void **module_argv, int module_argc, int is_loa ValkeyModuleCtx ctx; moduleCreateContext(&ctx, NULL, VALKEYMODULE_CTX_TEMP_CLIENT); /* We pass NULL since we don't have a module yet. */ if (onload((void *)&ctx, module_argv, module_argc) == VALKEYMODULE_ERR) { - serverLog(LL_WARNING, "Module %s initialization failed. Module not loaded", path); if (ctx.module) { + serverLog(LL_WARNING, "Module %s initialization failed. Module not loaded.", path); moduleUnregisterCleanup(ctx.module); moduleRemoveCateogires(ctx.module); moduleFreeModuleStructure(ctx.module); + } else { + /* If there is no ctx.module, this means that our ValkeyModule_Init call failed, + * and currently init will only fail on busy name. */ + serverLog(LL_WARNING, "Module %s initialization failed. Module name is busy.", path); } moduleFreeContext(&ctx); dlclose(handle); diff --git a/tests/unit/moduleapi/basics.tcl b/tests/unit/moduleapi/basics.tcl index 042e3474a..733e8e196 100644 --- a/tests/unit/moduleapi/basics.tcl +++ b/tests/unit/moduleapi/basics.tcl @@ -34,7 +34,12 @@ start_server {tags {"modules"}} { } } - test "Unload the module - test" { + test "Busy module name" { + assert_error {ERR Error loading the extension. Please check the server logs.} {r module load $testmodule} + verify_log_message 0 "*Module name is busy*" 0 + } + + test "Unload the module - basics" { assert_equal {OK} [r module unload test] } }