From: Cyrill Gorcunov <gorcunov@gmail.com> To: tml <tarantool-patches@dev.tarantool.org> Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Subject: [Tarantool-patches] [PATCH] func: clean the module cache on first load error Date: Fri, 13 Nov 2020 15:28:02 +0300 [thread overview] Message-ID: <20201113122802.253784-1-gorcunov@gmail.com> (raw) 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
next reply other threads:[~2020-11-13 12:28 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-13 12:28 Cyrill Gorcunov [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20201113122802.253784-1-gorcunov@gmail.com \ --to=gorcunov@gmail.com \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH] func: clean the module cache on first load error' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox