Unverified Commit 442e73ea authored by Meir Shpilraien (Spielrein)'s avatar Meir Shpilraien (Spielrein) Committed by GitHub
Browse files

Fix #10705, avoid relinking the same library twice. (#10706)

Set `old_li` to NULL to avoid linking it again on error.
Before the fix, loading an already existing library will cause the existing library to be added again. This cause not harm other then wrong statistics. The statistics that are effected  by the issue are:
* `libraries_count` and `functions_count` returned by `function stats` command
* `used_memory_functions` returned on `info memory` command
* `functions.caches` returned on `memory stats` command
parent a3df2777
...@@ -963,6 +963,7 @@ sds functionsCreateWithLibraryCtx(sds code, int replace, sds* err, functionsLibC ...@@ -963,6 +963,7 @@ sds functionsCreateWithLibraryCtx(sds code, int replace, sds* err, functionsLibC
old_li = dictFetchValue(lib_ctx->libraries, md.name); old_li = dictFetchValue(lib_ctx->libraries, md.name);
if (old_li && !replace) { if (old_li && !replace) {
old_li = NULL;
*err = sdscatfmt(sdsempty(), "Library '%S' already exists", md.name); *err = sdscatfmt(sdsempty(), "Library '%S' already exists", md.name);
goto error; goto error;
} }
......
...@@ -1141,6 +1141,23 @@ start_server {tags {"scripting"}} { ...@@ -1141,6 +1141,23 @@ start_server {tags {"scripting"}} {
r function stats r function stats
} {running_script {} engines {LUA {libraries_count 1 functions_count 1}}} } {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} { test {FUNCTION - function stats cleaned after flush} {
r function flush r function flush
r function stats r function stats
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment