Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] func: clean the module cache on first load error
@ 2020-11-13 12:28 Cyrill Gorcunov
  2020-11-13 12:29 ` Cyrill Gorcunov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Cyrill Gorcunov @ 2020-11-13 12:28 UTC (permalink / raw)
  To: tml; +Cc: Vladislav Shpilevoy

In case if we're loading a fresh module we put it
into a module's cache first which allows us to not
reload same module twice (say there could be several
functions in same module).

But if the module is loaded for the first time and
symbol resolution failed we continue keeping this
module loaded even if there may be no more use of
it. Thus make a cleanup if needed.

There is no portable way to verify via test as far
as I know, just manually via "lsof -p `pidof tarantool`".

Fixes #5475

Reported-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 src/box/func.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/box/func.c b/src/box/func.c
index 8087c953f..9909cee45 100644
--- a/src/box/func.c
+++ b/src/box/func.c
@@ -528,10 +528,9 @@ func_c_load(struct func_c *func)
 	struct func_name name;
 	func_split_name(func->base.def->name, &name);
 
-	struct module *module = module_cache_find(name.package,
-						  name.package_end);
-	if (module == NULL) {
-		/* Try to find loaded module in the cache */
+	struct module *cached, *module;
+	cached = module_cache_find(name.package, name.package_end);
+	if (cached == NULL) {
 		module = module_load(name.package, name.package_end);
 		if (module == NULL)
 			return -1;
@@ -539,11 +538,27 @@ func_c_load(struct func_c *func)
 			module_delete(module);
 			return -1;
 		}
+	} else {
+		module = cached;
 	}
 
 	func->func = module_sym(module, name.sym);
-	if (func->func == NULL)
+	if (func->func == NULL) {
+		if (cached == NULL) {
+			/*
+			 * In case if it was a first load we should
+			 * clean the cache immediately otherwise
+			 * the module continue being referenced even
+			 * if there will be no use of it.
+			 *
+			 * Note the module_sym set an error thus be
+			 * careful to not wipe it.
+			 */
+			module_cache_del(name.package, name.package_end);
+			module_delete(module);
+		}
 		return -1;
+	}
 	func->module = module;
 	rlist_add(&module->funcs, &func->item);
 	return 0;
-- 
2.26.2

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-26 21:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13 12:28 [Tarantool-patches] [PATCH] func: clean the module cache on first load error Cyrill Gorcunov
2020-11-13 12:29 ` Cyrill Gorcunov
2020-11-18 21:30 ` Vladislav Shpilevoy
2020-11-25  9:22   ` Alexander V. Tikhonov
2020-11-26 21:25 ` Vladislav Shpilevoy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox