Describe the bug load exists libraries will return ERR, bug the metric libraries_count & functions_count will increase
To reproduce
27.0.0.1:6379> FUNCTION stats
1) "running_script"
2) (nil)
3) "engines"
4) 1) "LUA"
2) 1) "libraries_count"
2) (integer) 1
3) "functions_count"
4) (integer) 1
127.0.0.1:6379> FUNCTION LOAD "#!lua name=mylib\nredis.register_function('knockknock', function() return 'Who\\'s there?' end)"
(error) ERR Library 'mylib' already exists
127.0.0.1:6379> FUNCTION stats
1) "running_script"
2) (nil)
3) "engines"
4) 1) "LUA"
2) 1) "libraries_count"
2) (integer) 2
3) "functions_count"
4) (integer) 2
127.0.0.1:6379>
Expected behavior https://github.com/redis/redis/blob/unstable/src/functions.c#L966 goto error and relink library, so in libraryLink increase stats->n_lib and stats->n_functions。
Comment From: enjoy-binbin
verified. i take a quick look, random thoughts:
1. dictAdd(lib_ctx->libraries, li->name, li); look like we need to check the return value
2. look like we need a flag like old_li_already_exists, when the lib already exists, set to 1, and libraryLink(lib_ctx, old_li) only if old_li_already_exists == 0
Comment From: MeirShpilraien
Thanks @enjoy-binbin, please let me know what you think about this fix: https://github.com/redis/redis/pull/10706