diff --git a/src/functions.c b/src/functions.c index 19d0d0c11e..c40761865e 100644 --- a/src/functions.c +++ b/src/functions.c @@ -963,6 +963,7 @@ sds functionsCreateWithLibraryCtx(sds code, int replace, sds* err, functionsLibC old_li = dictFetchValue(lib_ctx->libraries, md.name); if (old_li && !replace) { + old_li = NULL; *err = sdscatfmt(sdsempty(), "Library '%S' already exists", md.name); goto error; } diff --git a/tests/unit/functions.tcl b/tests/unit/functions.tcl index 62c070f906..e9aeda16bf 100644 --- a/tests/unit/functions.tcl +++ b/tests/unit/functions.tcl @@ -1141,6 +1141,23 @@ start_server {tags {"scripting"}} { r function stats } {running_script {} engines {LUA {libraries_count 1 functions_count 1}}} + test {FUNCTION - test function stats on loading failure} { + r FUNCTION FLUSH + + r FUNCTION load {#!lua name=test1 + redis.register_function('f1', function() return 1 end) + redis.register_function('f2', function() return 1 end) + } + + catch {r FUNCTION load {#!lua name=test1 + redis.register_function('f3', function() return 1 end) + }} e + assert_match "*Library 'test1' already exists*" $e + + + r function stats + } {running_script {} engines {LUA {libraries_count 1 functions_count 2}}} + test {FUNCTION - function stats cleaned after flush} { r function flush r function stats