Commit c7336da4 authored by Marek Vavruša's avatar Marek Vavruša Committed by Marek Vavruša

daemon/engine: close cache before closing modules

this fixes a problem when module is unloaded at runtime
and active
parent d5272b4b
......@@ -237,6 +237,8 @@ void engine_deinit(struct engine *engine)
}
network_deinit(&engine->net);
kr_cache_close(engine->resolver.cache);
engine->resolver.cache = NULL;
/* Unload modules. */
for (size_t i = 0; i < engine->modules.len; ++i) {
......@@ -249,7 +251,6 @@ void engine_deinit(struct engine *engine)
lua_close(engine->L);
}
kr_cache_close(engine->resolver.cache);
}
int engine_pcall(lua_State *L, int argc)
......
......@@ -53,7 +53,7 @@ namedb_t *kr_cache_open(void *opts, mm_ctx_t *mm)
void kr_cache_close(namedb_t *cache)
{
if (cache) {
if (cache && db_api) {
db_api->deinit(cache);
}
}
......
......@@ -40,9 +40,15 @@ int kmemcached_init(struct kr_module *module)
return kr_ok();
}
int lmemcached_deinit(struct kr_module *module)
int kmemcached_deinit(struct kr_module *module)
{
struct engine *engine = module->data;
/* It was currently loaded, close cache */
if (kr_cache_storage == namedb_memcached_api) {
kr_cache_close(engine->resolver.cache);
engine->resolver.cache = NULL;
}
/* Prevent from loading it again */
for (unsigned i = 0; i < engine->storage_registry.len; ++i) {
struct storage_api *storage = &engine->storage_registry.at[i];
if (strcmp(storage->prefix, "memcached://") == 0) {
......@@ -50,9 +56,6 @@ int lmemcached_deinit(struct kr_module *module)
break;
}
}
if (kr_cache_storage == namedb_memcached_api) {
kr_cache_storage_set(NULL);
}
return kr_ok();
}
......
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